<div id="myDiv">
<ul class="purpose">
@{
var purpose = CommonMethod.getPurpose("");
for(int i=0;i<10 && i<purpose.Count();i++)
{
<li><a href="#" >@purpose[i].Text</a></li>
}
}
</ul>
</div>
从列表中选择上述单一用途时,它将在 ajax 表单下方显示以进行更新
@using (Ajax.BeginForm("UpdatePurpose", "Admin", new AjaxOptions { UpdateTargetId = "updateDiv" }))
{
<div class="profile">
@Html.Hidden("PurposeID")
<table>
<tr>
<td>Purpose</td>
<td>:</td>
<td> width="30%">@Html.TextBox("Description")</td>
</tr>
<tr>
<td>Admin Password</td>
<td>:</td>
<td>@Html.Password("Passwd1")</td>
</tr>
</table>
<input type="submit" value="submit" />
</div>
}
在 Subting 之后调用下面的动作
[HttpPost]
public ActionResult UpdatePurpose(string PurposeID,string Description, string Passwd1)
{
if (Request.IsAjaxRequest())
{
if (!Membership.ValidateUser(User.Identity.Name, Passwd1))
{
ModelState.AddModelError("", "Invalid Admin Password");
}
if (ModelState.IsValid)
{
var id = Convert.ToByte(PurposeID);
var pur = db.Purposes.Where(p => p.PurposeID == id).SingleOrDefault();
pur.Description = Description;
db.SaveChanges();
ViewBag.Result = "Data Updated Successfully.";
return View();
}
}
return View();
}
在提交上面的 ajax 表单更新目的时,如果管理员密码无效,我想显示验证消息错误,并且如果模型状态有效,我想加载 myDiv 内容并向用户提供成功更新消息