Ajax applications in asp.net mvc-practical tips

Source: Internet
Author: User
Tags object model

Ajax application in asp.net mvc

First of all, in asp.net mvc using its own AJAX features, you must import 2 JS files (order can not be reversed):

                    

asp.net MVC provides 2 common Ajax-assisted methods.

Ajax.actionlink

This helper method is used to generate a hyperlink with AJAX functionality on the page.

                    

There is an argument for the Ajaxoptions type in the helper method, which includes the following properties:

Confirm: Before sending an AJAX request, pop Up the confirmation dialog box, which is the prompt message in the Settings dialog httpmethod: The type used to set the request: Get| Postupdatetargetid: The result of setting the server response is updated to the target element in the page Idinsertionmode: used to set the server's corresponding results to be inserted into the updated element, its value can include 3 kinds:

Insertionmode.replace: Replaces old values with new values (default)

Insertionmode.insertafter: Inserts a new value at the bottom of the target element

Insertionmode.insertbefore: Inserts a new value at the top of the target element

Onbegin: When the AJAX request executes, the JS function onsuccess: When the AJAX request succeeds, the JS function that executes onfailure: when the AJAX request fails, the JS function that executes oncomplate: when the AJAX request is complete, The JS function executed (regardless of whether the request failed or succeeds) Loadingelementid: During the AJAX request, you can display a friendly hint that sets the hint element's idloadingelementduration: When the prompt element is displayed and hidden , you can perform an animation that sets the animation execution time for the hint element

                    

Ajax.beginform

This Ajax helper method is used to submit the form data in an AJAX manner.

                    

Other

How do I load a partial view on a page?

Mode one: Call Html.renderpartial ("ViewName")

Mode two: Call Html.renderaction ("ActionName")

The difference between them is shown in the following illustration:

                    

When to use renderaction and when to use renderpartial?

If you need to pass data to a view, and you don't have data to pass in the original view, you need to call renderaction.

Note: Html.renderpartial has several overloaded forms, listed below for its 2 common forms:

Html.renderpartial ("Name of the distribution View")

Html.renderpartial ("Name of Partial View", object model data)

How do I get a JSON-formatted string from the server?

The server's action method returns a value type of Jsonresult, and the Controller.json () helper method can be invoked inside the method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.