MVC3----Ajax Helper method

Source: Internet
Author: User
Tags actionlink

===================ajax.actionlink

The ActionLink method can create an anchor label with one-step behavior.

For example:

Give the page a link, click on the link to display the information on the current page, instead of opening a new page


-- View Code:

@Ajax. ActionLink ("Ajax",//Page link name "Getajax",//Controller in method new ajaxoptions{Updatetargetid = "Getajax",//label to replace INSERTIONMO de = insertionmode.replace,//insert mode: replace label HttpMethod = "Get"//get request}) <!--manipulated label--><div id= "Getajax" ></ Div>

-- Controller code: (Returns a partial view to the foreground, need to create a getajax.cshtml view in the view)

Public ActionResult Getajax () {return this. Partialview ();}



===================ajax form

Case: Querying Data asynchronously

-- View Code:

<!--Ajax execution fails when executing a script--><script>    function loadfailure ()  {         $ ("#div1"). Text ("Failed to load");     }</script>@ using  (Ajax.beginform ("Personsearch",//Controller method      "Personerror",//Controller      new ajaxoptions ()  { //ajaxoptions object     httpmethod= "Get",//Submission method      insertionmode = insertionmode.replace,//Insert mode: Replace label      updatetargetid =  "Div1",//Operating label     LoadingElementId =  "Ajax-load",// When you click the Submit button, a status of the load is displayed (GIF loading image is used here)     onfailure= "Loadfailure"//execute a script when Ajax execution fails)) {     <input type= "text"  name= "Q"  />    <input  Type= "Submit"  value= "commit"  />    <!--loading status (GIF loading image is used here)-->     }<!--operated label-- <div id= "Div1" ></div>

-- Controller code:(return a partial view to the foreground, you need to create a personsearch.cshtml view in the View )

Public ActionResult Personsearch (string q) {var list = db. Schooltypes.where (r = r.st_name = = q). Select (r = r).    ToList (); return Partialview (list);}


This article is from the "program Ape's Home--hunter" blog, please be sure to keep this source http://962410314.blog.51cto.com/7563109/1609688

MVC3----Ajax Helper 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.