当前位置 > 首页 > Asp.net

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

2012-12-8 21:01:00来源: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.





  • 解决手机Windows Mobile系统无法获取DRM License问题

    2009-7-16 11:16:00

    近段时间在做手机WAP视频项目时,用户下载DRM加密视频时需要进行License预发放,发现DRM License无法获取成功。 页面获取License代码如下: License获取ob

  • .Net 异步处理温习

    2010-1-15 0:51:00

    阅读: 91 评论: 0 作者: Virtual Coder 发表于 2010-01-14 23:00 原文链接 这几天,看WF本质论,里面提到了.net的异步处理。由于里面使用的是代码片

  • 实现无人值守流程审批管理

    2007-9-27 21:38:00

    你想实现,不登陆网站就能审批文件?你想实现不用去公司就可以 解决自己的审批任务? 我可以给你一个 很好的思路。 我们可以很好的利用手机短信的业务来实现事件通过Ws回调, 只需要一个短信

  • In Memory SQLite + Unit Test + FluentNHibernate

    2010-7-11 16:37:00

    UPDATE: I have forked fluent NH here: http://github.com/stefansedich/fluent-nhibernate, and add

  • Understanding LINQ to Objects (7) Query Methods Internals

    2010-3-18 14:08:00

    This post explains how are the LINQ to Objects standard query methods implemented. Once again, it

  • Stress Managment - 压力管理

    2009-5-11 17:15:00

    有本文是因为最近HBR发布有一篇文章: Watch Out for Stress in Your People 。 认知压力   毋庸讳言,压力广泛存在于IT行业,屡见不鲜的自

  • 上周热点回顾(12.21-12.27)

    2009-12-28 11:59:00

    阅读: 776 评论: 3 作者: 博客园团队 发表于 2009-12-28 09:20 原文链接 热点随笔: ·  理性声音少吗? ·

  • Silverlight3系列(四)数据绑定 Data Binding 1

    2010-1-27 12:26:00

    阅读: 20 评论: 0 作者: virus 发表于 2010-01-27 11:55 原文链接   今天我们讨论的是Silverlight3中的数据绑定,内容来自 《Pro Silver

  • How to register the F# project with VS 2008 Beta 2

    2007-9-20 0:56:00

    In this post I mentioned that F# compiler doesnt register its project correctly with VS 2008 Beta 2

  • 多线程Singleton单件模式

    2009-4-13 12:59:00

    Singleton模式是最简单的模式,比较汗颜的是自己一直以来使用的是单线程的Singleton模式,最近在听了李建忠老师的模式讲座录像后,才发现自己一直没注意到这点。这个录像讲座在后面给出了链接地