ASP.NET MVC 4 Binding Issue

Yesterday, I found the important issue in ASP.NET MVC 4. I was trying to find the issue. When I googled, I found this important blog too about how to optimize performance in MVC 4 with bundling. For almost 3 hours, finally I found the problem, the issue is present in System.Web.PrefixContainer class which is used by both ASP.NET MVC and ASP.NET Web API assembly. This bug can be a breaking change for you if you upgraded your application to ASP.NET MVC 4 and your application model properties using the convention available in the above thread. So, I have created a package which will fix this issue both in ASP.NET MVC and ASP.NET Web API. In this article, I will show you how to use this package

First, what you need is create ASP.NET MVC 4 and install ImranB.ModelBindingFix NuGet package. Then, add this using statement on your global.asax.cs file,

using YourName.ModelBindingFix;

Then, just add this line in Application_Start method

Fixer.FixModelBindingIssue();
// For fixing only in MVC call this
//Fixer.FixMvcModelBindingIssue();
// For fixing only in Web API call this
//Fixer.FixWebApiModelBindingIssue();

The line above will fix your binding issue. If you are using FormDataCollection.ReadAs extension method then you should use FormDataCollection.FixedReadAs instead to avoid this bug. If you are using Html.Action or Html.RenderAction then you should use Html.FixedAction or Html.FixedRenderAction instead to avoid this bug.

Hope it help