ASP. NET MVC Advanced Three

Source: Internet
Author: User

One, AJAX applications in ASP.

First, with the Ajax feature in ASP. 2 JS files must be imported (the order cannot be reversed):

ASP. NET MVC provides 2 common Ajax helper methods.

Ajax.actionlink

This helper method is used to generate hyperlinks on the page that have AJAX functionality.

There is an ajaxoptions type parameter in the helper method, which includes the following properties:

    • Confirm: Before sending an AJAX request, a confirmation dialog pops up, which is the prompt message in the Settings dialog box
    • HttpMethod: The type used to set the request: Get| Post
    • Updatetargetid: The result of setting the server response is updated to the target element ID in the page
    • Insertionmode: Used to set how the server's corresponding results are inserted into the element being updated, its value can include 3 kinds:

Insertionmode.replace: Replace old value with new value (default value)

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: The JS function executed before the AJAX request is executed
    • Onsuccess: The JS function that executes when the AJAX request is executed successfully
    • OnFailure: When the AJAX request fails, the JS function that is executed
    • Oncomplate: When the AJAX request is complete, the JS function executed (regardless of the request failure or success, will be executed)
    • Loadingelementid: During an AJAX request, you can display a friendly hint that sets the ID of the cue element
    • Loadingelementduration: The hint element can be animated when shown and hidden, which sets the animation execution time for the cue element

Ajax.beginform

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

Other

How to load a partial view in a page ?

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

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

The difference between them is as follows:

When to use Renderaction, When to use renderpartial?

If you need to pass data to the view, and there is no data in the original view that needs to be passed, you need to call renderaction.

Note : Html.renderpartial has a variety of overloaded forms, listed below for its 2 common forms:

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

Html.renderpartial ("Name of the partial view", object model data)

How to get a segment from the server JSON string in format ?

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

ASP. NET MVC Advanced Three

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.