问题
I'm starting a new ASP.NET MVC 3 project and am going to implement some screens that are read only by default but allow the user to edit information by clicking on an Edit button. I want these screens to be AJAXed. I have previously used the jQuery Form Plugin to implement similar screens on an ASP.NET MVC 2 project.
I've just discovered the existence of Ajax.BeginForm()
and was wondering whether I should use that since it is built in, instead of using the jQuery Form Plugin. I've done a Google search on the difference between the two techniques but couldn't find anything.
What I would like to know is which one (or a different one altogether) should I use with ASP.NET MVC 3.
What are the best practices and libraries for implementing AJAX forms in ASP.NET MVC?
What are the strengths and weaknesses of Ajax.BeginForm
vs the jQuery Form Plugin?
回答1:
I would use the Form Plugin.
In MVC 3, the Ajax helper is basically implemented using jQuery Ajax. (See Brad's Wilsons post on unobtrusive Ajax in MVC 3.) The upside to using the Form Plugin is that you'll have more control over your pages and you don't have to use the clunky BeginForm API.
回答2:
If you're going to use Ajax.BeginForm, I would suggest turning on UnobtrusiveJavaScript. One upside of using the built in mvc helpers is that it's one less library you need to include. Otherwise an upside of the jQuery.Form plugin I could see is more control of your event handling. As you don't have to worry about the MVC ajax form firing before you have a chance to do something.
来源:https://stackoverflow.com/questions/4911834/asp-net-mvc-3-ajax-beginform-vs-jquery-form-plugin