当前位置 > 首页 > Asp.net

Fixing the Model Binding issue of ASP.NET MVC 4 and ASP.NET Web API

12/8/2012 9:01:00 PM来源:Asp.net

        Introduction:


                    Yesterday when I was checking ASP.NET forums, I found an important issue/bug in ASP.NET MVC 4 and ASP.NET Web API. The issue is present in System.Web.PrefixContainer class which is used by both ASP.NET MVC and ASP.NET Web API assembly. The details of this issue is available in this thread. 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.  


        Description:


                    Create or open an ASP.NET MVC 4 project and install ImranB.ModelBindingFix NuGet package. Then, add this using statement on your global.asax.cs file,


         using ImranB.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();

.



                    This line will fix the model binding issue. If you are using Html.Action or Html.RenderAction then you should use Html.FixedAction or Html.FixedRenderAction instead to avoid this bug(make sure to reference ImranB.ModelBindingFix.SystemWebMvc namespace). If you are using FormDataCollection.ReadAs extension method then you should use FormDataCollection.FixedReadAs instead to avoid this bug(make sure to reference ImranB.ModelBindingFix.SystemWebHttp namespace). The source code of this package is available at github



        Summary:


                    There is a small but important issue/bug in ASP.NET MVC 4. In this article, I showed you how to fix this issue/bug by using a package. Hopefully you will enjoy this article too.





  • Spring.NET 1.3.1 正式版已发布

    12/22/2010 2:07:00 PM

    Spring.NET 1.3.1 下载地址为 http://www.springframework.net/download.html 正如已经 提到的 其他地方, 这将

  • 根据Live ID 计算 Live Messenger 账户唯一ID的方法

    2/5/2009 5:25:00 PM

    摘要: 不容易啊,总算是找到了。基本算法应该是找到了,大概情况是这样的: 1) 将 Live ID 转换为ANSI字符串; 2)将这个字符串的字符全部变为小写; 3) 遍历这个字符串,先将累加结果

  • Objective-C --- 1,前言

    3/27/2009 6:23:00 PM

    摘要: 1,前言相信iPhone不久就要在国内发布了,和我们在国内可以通过正规渠道买得到的iPod Touch一样,iPhone也是一个激动人心的产品。iPhone发布的同时,基于iPhone的程序

  • iPhone Apps using Microsoft .NET

    12/2/2009 6:57:00 AM

    My good friend Wally McClure has written a short eBook on “ Building iPhone and iPod touch Applic

  • 写作目的和内容决定技术文章贴代码的方式

    8/25/2009 1:29:00 PM

    摘要: 早上看了一位朋友的文章,这位朋友在文章中犯了愁,他说:我之前写过一些文章,因为没有贴代码,----准确的说,是没有贴全代码而遭人骂。,一些人直接给文章回复说那么多废话干什么,快贴代码,把代码

  • CodeSmith将模板文件批量生成文件的方法

    6/20/2009 11:15:00 AM

    以前写codeSmith模板的时候,如果直接像asp一样混排编写的话,代码输出来codeSmith中,不知道怎么保存到文件,后来把所有要输出的模板文字都用stringBuiler串接起来然后IO到文

  • Installing DotNetNuke on Windows Home Server

    10/30/2009 10:57:00 AM

    So I’m a newbie when it comes to Windows Home Server but I’m quite seasoned when it comes to DotNet

  • .NET FX库源代码

    10/8/2007 3:56:00 PM

    [原文地址] .NET FX Libraries Source Code [原文发表时间] Wednesday, October 03, 2007 2:18 PM

  • 敏捷开发思想之拥抱变化

    6/21/2009 12:50:00 PM

    秉承敏捷宣言的精神(个体与交付重于过程和工具;可用的软件重于完备的文档;客户协作重于合同谈判;响应变化重于遵循计划),我认为,敏捷开发大致应该体现如下的思想:拥抱变化、自我组织、简单最好、客户至上、

  • 我的轻型ORM实现

    4/2/2007 10:49:00 PM

    摘要: 一个轻型的ORM实现,不会让你失望 :) 阅读全文 Michael.Yang 2007-04-02 21:40 发表评论