Ajax. BeginForm: submits forms asynchronously and updates data. ajax. beginform forms
Using (Ajax. BeginForm ("GetBasicInformation", "Employee ",//
New AjaxOptions {UpdateTargetId = "basicInfo", // sets the ID of the HTML element. The content received from the server is inserted into the element.
LoadingElementId = "loading", // specifies the ID of the HTML element, which is the HTML element to be displayed during the execution of the ajax request
LoadingElementDuration = 3000, // specifies the animation duration, used to show the elements specified by LoadingElementId, in milliseconds
Url = Url. action ("GetBasicInformation"), // sets the requested server URL. This effect: if JavaScript is not enabled, create a form element that is passed back to the original Action method to ensure elegant degradation.
HttpMethod = "Post"}, // http Method of the request
New {@ class = "profileForm", id = "BasicInformation "}))//
{
}
The source code in the browser in the previous section is as follows:
<Form action = "/Employee/GetBasicInformation? Length = 8"
Class = "profileForm" data-ajax = "true"
Data-ajax-loading = "# loading"
Data-ajax-loading-duration = "3000"
Data-ajax-method = "Post"
Data-ajax-mode = "replace"
Data-ajax-update = "# basicInfo"
Data-ajax-url = "/Employee/GetBasicInformation"
Id = "BasicInformation" method = "post">
The Controller code is as follows:
[HttpPost]
Public PartialViewResult GetBasicInformation ()
{
.......
.......
.......
Return PartialView ();
}
PartialViewResult. ascx contains the View content to be refreshed.
For example:
<H2> Basic Information <Span class = "c_edit" id = "spantest"> </span>
<Div class = "basicShow" id = "basicshow">
<Span> <% = Model. NAME %> <% = Model. SEX %> <% = Model. EDUCATION_BACKGROUND %> <% = Model. WORK_EXPERIENCE %> <br>
<% = Model. PHONENUMBER %> <% = Model. EMAIL %> <% = Model. SITUATIONID. SITUATION %>
<Br>
</Span>
<Div class = "m_portrait">
<Div> </div>
</Div>
</Div>