Are MicrosoftAjax.js, MicrosoftMvcAjax.js and MicrosoftMvcValidation.js obsolete as of ASP.NET MVC 3?

前端 未结 2 1164
灰色年华
灰色年华 2020-11-27 03:14

Are MicrosoftAjax.js, MicrosoftMvcAjax.js and MicrosoftMvcValidation.js obsolete as of ASP.NET MVC 3? I haven\'t been able to find muc

2条回答
  •  佛祖请我去吃肉
    2020-11-27 03:54

    Yes, all Microsoft* helpers are obsolete in ASP.NET MVC 3. For me they have always been obsolete but now at least Microsoft made this official and replaced them with jQuery.

    2 new functionalities have been introduced

    
        
        
        
    
    

    The first is UnobtrusiveJavaScriptEnabled. This means that if you enable this functionality in your web.config (its enabled by default when you create a new ASP.NET MVC 3 application), all the Ajax.* helpers such as Ajax.BeginForm and Ajax.ActionLink will emit HTML5 data-* attributes on their respective DOM elements instead of mixing javascript with markup. Then you should include the jquery.unobtrusive-ajax.js script to your page which will parse those attributes and use jQuery to unobtrusively AJAXify them.

    The second is ClientValidationEnabled which is also enabled by default. The same way unobtrusive javascript works, when you enable this setting all helpers that generate input fields will emit HTML5 data-* attributes on them. Then you include jquery.validate.js and jquery.validate.unobtrusive.js scripts to make them work, such as in your _Layout.cshtml. They must appear in this order, and they must be after jquery is loaded:

    
    
    
    

    So in ASp.NET MVC 3 you can forget about all Microsoft* scripts. Remove them from your site. Delete those files.

提交回复
热议问题