ASP.NET AJAX vs jQuery in ASP.NET MVC

后端 未结 10 1000
日久生厌
日久生厌 2020-12-07 19:08

Which one is better to use in ASP.NET MVC?

相关标签:
10条回答
  • 2020-12-07 19:29

    Personally, despite the HtmlHelper support for ASP.NET Ajax, I find jQuery ajax in conjunction with the JQuery forms plugin to be the nicest way to do ajax form posts in ASP.NET MVC.

    e.g. with a jquery call on an html product list page with a form for each product allowing the item to be added to a basket, a single line of jquery code can 'ajaxify' all the forms on the page

    $(".productListItem form").ajaxForm({ target: '#extraInfoSection' });
    

    combined with a simple 'IsAjaxRequest' property on a controller base class that checks the headers:

    Request.Headers["X-Requested-With"] == "XMLHttpRequest"
    

    and some logic in the Controller to return the correct response type:

    return IsAjaxRequest ? (ActionResult) View("BasketPartial", basket) : new RedirectBackToReferrerActionResult();
    

    you have a form that works even with javascript turned off and no ASP.NET Ajax involved.

    0 讨论(0)
  • 2020-12-07 19:39

    There is a variant of ASP.NET AJAX for MVC -- used with the AjaxHelper and extensions. This works well in concert with jQuery. I have instances where I use both on the same page; using MVC AJAX to update a DIV based clicking a button and using jQuery to get JSON data for a different operation on the same page. Standard ASP.NET AJAX (UpdatePanels, etc.) should be used in the WebForms world, not in MVC.

    0 讨论(0)
  • 2020-12-07 19:39

    Use ASP.NET AJAX with Web Forms and jQuery with ASP.NET MVC

    0 讨论(0)
  • 2020-12-07 19:39

    Another alternative you probably could look at is Ajax.NET, http://www.ajaxpro.info/. I reckon it's better than ASP.NET AJAX for WebForms. It's runnable under MVC as well.

    0 讨论(0)
  • 2020-12-07 19:39

    First of all, you could use either, as long as when you are talking about Microsoft Ajax, you are only referring to the client library. You can use the MS Ajax client library and most of the toolkit extenders without any server side controls. I have built a pretty big application using web forms and Microsoft Ajax then converted it to MVC/jquery. I found that I was using less and less of the features in the MS Ajax library. There is so much available with plugins, that its making even the ajax toolkit obsolete.

    If you are talking about MS Ajax using update panels etc, then I would say no, you can't use them in MVC. In fact, don't use them at all! update panels are simulated ajax, the page still goes through its lifecylce almost defeating the purpose of using ajax.

    0 讨论(0)
  • 2020-12-07 19:40

    I would like to mention that Microsoft supports JQuery, and they will make support for it in upcoming versions of Visual Studio. For more information please visit http://live.visitmix.com/. ASP.NET AJAX and jQuery does not overlap much, so you would like to use both.

    0 讨论(0)
提交回复
热议问题