当前位置 > 首页 > 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.





  • Using 2 Tables Joined with LINQ as data source without anonymous cast error in databond method

    2009-11-4 18:01:00

    Yesterday one of our project team member faced a challenge of using an anonymous data that is retur

  • 国内项目开发过程分析总结

    2007-8-30 19:49:00

    我最近想写一篇关于国内项目开发过程分析的总结,目前列出了这些项目的一些阶段,希望得到大家的支持,多提意见。我会近期完善本文的。 希望dudu让我放首页收集下各位朋友的意见 谢谢!!!

  • OOo on ready---VB篇

    2009-8-16 23:53:00

    摘要: 随着经济的不景气,越来越多的公司将办公软件从较昂贵的MS Office转换为便宜甚至免费的Open Office.org(简称OOo),毕竟OOo几乎可以满足所有的日常办公需求,并且兼容MS

  • More reminders / gotchas from the trenches with Azure

    2009-3-27 18:23:00

    Ive been working on setting up my VPC for Azures March CTP. This is a fresh install. I had everythi

  • 设计模式--Prototype

    2007-3-13 11:35:00

    摘要: 二、概述 在软件系统中,有时候面临的产品类是动态变化的,而且这个产品类具有一定的等级结构。这时如果用工厂模式,则与产品类等级结构平行的工厂方法类也要随着这种变化而变化,显然不大合适。那么如

  • 学习jQuery(一),做的第一个可拖动列的Grid

    2009-9-6 2:54:00

    摘要: 想想前些日子面试时人家问我会jQuery吗?我说不会,问我会用.net GridView吗?我说用的少,都直接写CSS.于是被拒之门外...呵呵,玩笑,当然还有其他原因啦。最近没工作没事干,

  • WPF自定义控件 —— 复合控件(中国象棋联机版)

    2009-5-6 13:04:00

    摘要: 你是否在小时和父亲一起对弈,享受父亲的慈爱或严厉,你是否还记得和邻家朋友间的激烈切磋,战后的拍肩言和,或是在竞赛气氛中的喜悦或无奈,自己做一款游戏,练习技术的同时,也留下了一份回忆;对于自己

  • FMS3系列(四):在线视频录制、视频回放

    2009-4-26 20:37:00

    使用Flash/Flex+FMS实现在线视频录制、视频回放的很简单的。通过阅读API文档后基本都可以实现这个功能,本文也意在抛砖引玉,希望对刚入手这块的朋友有所帮助。 首先建立好Flash(A

  • Exploring Dynamic Data: Textual attributes for business logic

    2009-12-22 7:57:00

    Index to this series of articles Business logic is applied to your Entity classes (objects

  • T4 Template for generate Table Script from XSD

    2009-7-10 17:13:00

    The below T4 template will generate Create Table script from a XSD file. The Template will create a