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.