Why are Redirect Results not allowed in Child Actions in Asp.net MVC 2

The limitation exists because MVC has already started rendering a view to the client. The effect of redirecting from this point is undefined. It could work perfectly, it could continue rendering the original view without redirecting, it could throw a different exception, etc. Since the result of performing this action is undefined, the framework blocks … Read more

Asp.Net MVC 2 – Bind a model’s property to a different named value

In response to michaelalm’s answer and request – here’s what I’ve ended up doing. I’ve left the original answer ticked mainly out of courtesy since one of the solutions suggested by Nathan would have worked. The output of this is a replacement for DefaultModelBinder class which you can either register globally (thereby allowing all model … Read more

Has anyone implement RadioButtonListFor for ASP.NET MVC?

Here is the usage in the aspx page <%= Html.RadioButtonListFor(m => m.GenderRadioButtonList)%> Here is the view model public class HomePageViewModel { public enum GenderType { Male, Female } public RadioButtonListViewModel<GenderType> GenderRadioButtonList { get; set; } public HomePageViewModel() { GenderRadioButtonList = new RadioButtonListViewModel<GenderType> { Id = “Gender”, SelectedValue = GenderType.Male, ListItems = new List<RadioButtonListItem<GenderType>> { new … Read more

How to create Custom Data Annotation Validators

To create a custom data annotation validator follow these gudelines: Your class has to inherit from System.ComponentModel.DataAnnotations.ValidationAttribute class. Override bool IsValid(object value) method and implement validation logic inside it. That’s it. IMPORTANT Caution Sometimes developers check that value is not null/empty and return false. This is usually incorrect behaviour, because that’s on Required validator to … Read more

Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?

The answer was staring me in the face. ASP.NET Session State Overview: Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID … Read more

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

How to change default validation error message in ASP.NET MVC?

Apparently my question was already answered at How to replace the default ModelState error message in Asp.net MVC 2? . I’ll summarize it here: Create App_GlobalResources folder for your project (right click to project -> Add -> Add ASP.NET folder -> App_GlobalResources). Add a resx file in that folder. Say MyNewResource.resx. Add resource key PropertyValueInvalid … Read more