using (Ajax.BeginForm("GetBasicInformation", "Employee", //new AjaxOptions { UpdateTargetId = "basicInfo", //設置HTML元素的ID,從伺服器接收的內容將被插入到該元素中LoadingElem...
using (Ajax.BeginForm("GetBasicInformation", "Employee", //
new AjaxOptions { UpdateTargetId = "basicInfo", //設置HTML元素的ID,從伺服器接收的內容將被插入到該元素中
LoadingElementId="loading",//指定HTML元素的ID,這是執行ajax請求其間要顯示的HTML元素
LoadingElementDuration = 3000, //指定動畫的持續時間,用於顯露由LoadingElementId指定的元素,單位為毫秒
Url = Url.Action("GetBasicInformation"), //設置所請求的伺服器端URL,此項效果:如果未啟用JavaScript,則創建一個回遞給原始動作方法的form元素,確保優雅降級
HttpMethod = "Post" },//請求的http方法
new { @class = "profileForm", id = "BasicInformation" }))//
{
}
上段的瀏覽器中源代碼效果如下:
<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">
控制器中代碼如下:
[HttpPost]
public PartialViewResult GetBasicInformation()
{
。。。。。。。
。。。。。。。
。。。。。。。
return PartialView();
}
PartialViewResult.ascx中是你要刷新的視圖內容
例如:
<h2>基本信息</h2>
<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>
<img width="120" height="120" alt="jason" src="<%=Url.Content("~/style/images/default_headpic.png") %>">
</div>
</div>