AJAX application in ASP. net mvc, mvcajax

Source: Internet
Author: User
Tags actionlink

AJAX application in ASP. net mvc, mvcajax

I. AJAX applications in ASP. NET MVC

First, to use the built-in ajax function in ASP. net mvc, you must import two js files (the order cannot be reversed ):

                    

ASP. net mvc provides two commonly used ajax auxiliary methods.

Ajax. ActionLink

This auxiliary method is used to generate a hyperlink with ajax functions on the page.

                    

There is an AjaxOptions type parameter in the auxiliary method, which includes the following attributes:

Confirm: before sending an ajax request, a confirmation dialog box is displayed. This attribute is the prompt message HttpMethod: used to set the request type: Get | PostUpdateTargetId: used to set the server response result to update to the target element IDInsertionMode on the page: Used to set how the server's corresponding results are inserted into the updated element. The value can include three types:

InsertionMode. Replace: Replace the old value with the new value (default)

InsertionMode. InsertAfter: Insert the new value to the bottom of the target element.

InsertionMode. InsertBefore: Insert the new value to the top of the target element.

OnBegin: The js function OnSuccess executed before the ajax request is executed: When the ajax request is successfully executed, the js function OnFailure: When the ajax request fails, the js function OnComplate: after the ajax request is complete, the executed js function (whether the request fails or succeeds, it will be executed) LoadingElementId: a friendly prompt is displayed during the ajax request, this attribute is used to set the IDLoadingElementDuration of the prompt element. When the prompt element is displayed or hidden, an animation can be executed. This attribute is used to set the animation execution time of the prompt element.

                    

Ajax. BeginForm

This ajax helper method is used to submit form data in ajax mode.

                    

Others

How do I load the segment view on the page?

Method 1: call Html. RenderPartial ("viewName ")

Method 2: call Html. RenderAction ("actionName ")

The differences between them are shown in:

                    

When to use RenderAction and RenderPartial?

If you want to pass data to a view without passing data in the original view, you need to call RenderAction.

Note: Html. RenderPartial can be reloaded in multiple ways. The following lists two common methods:

Html. RenderPartial ("Name of the distributed View ")

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

How can I obtain a json string from the server?

The Return Value Type of the server Action method is JsonResult, and the Controller. Json () auxiliary method can be called within the method.


Cross-origin ajax in aspnet MVC3/MVC4 Mode

I found an example where jquery ajax is used in webform for cross-origin calling. You can check it to see if there are any parameters missing:
$. Ajax ({type: "get", async: false, url: "www.xxx.com/ajax.do", dataType: "jsonp", jsonp: "callbackparam ", // The parameter jsonpCallback of the function name used by the server to receive callback calls: "success_jsonpCallback", // The function name success of callback: function (json) {alert (json ); alert (json [0]. name) ;}, error: function () {alert ('fail ') ;}}); the code on the server side is as follows:
Public void ProcessRequest (HttpContext context) {context. response. contentType = "text/plain"; String callbackFunName = context. request ["callbackparam"]; context. response. write (callbackFunName + "([{name: \" John \ "}])");} This is the case in webform. I don't know if this is the case in mvc. Check it out.


How does aspnet mvc implement ajax?

Jquery's ease of use
However, you can also use @ ajax. actionlink @ ajax. beginform

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.