How to achieve a dynamic controller and action method in ASP.NET MVC?

Absolutely! You’ll need to override the DefaultControllerFactory to find a custom controller if one doesn’t exist. Then you’ll need to write an IActionInvoker to handle dynamic action names. Your controller factory will look something like: public class DynamicControllerFactory : DefaultControllerFactory { private readonly IServiceLocator _Locator; public DynamicControllerFactory(IServiceLocator locator) { _Locator = locator; } protected override … Read more

Firefox 6 Infinite Page Refresh With Page With Hash Tags

Turns out, this is an issue with an old version of MicrosoftAjax.js (the one that comes installed with Asp.Net MVC 2). Open up the MicrosoftAjax.debug.js file and check the file version number. The top of this file will look like this if this is your problem: // Name: MicrosoftAjax.debug.js // Assembly: System.Web.Extensions // Version: 4.0.0.0 … Read more

ModelState.AddModelError – How can I add an error that isn’t for a property?

I eventually stumbled upon an example of the usage I was looking for – to assign an error to the Model in general, rather than one of it’s properties, as usual you call: ModelState.AddModelError(string key, string errorMessage); but use an empty string for the key: ModelState.AddModelError(string.Empty, “There is something wrong with Foo.”); The error message … Read more

Are

the colon syntax means you’ll be html encoded automatically: http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx They couldn’t just html encode all the existing <%= blocks, because things that are already properly encoded (which is hopefully most of the projects out there) would look strange.

Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable

Start with you DbContext, create a new file called Database.cs: Database.cs public class Database : DbContext { private IDbSet<Post> _posts; public IDbSet<Post> Posts { get { return _posts ?? (_posts = DbSet<Post>()); } } public virtual IDbSet<T> DbSet<T>() where T : class { return Set<T>(); } public virtual void Commit() { base.SaveChanges(); } } Define … Read more