AJAX enabled & disabled
@model string
@{
ViewBag.Title = "GetPeople";
AjaxOptions ajaxOpts = new AjaxOptions { UpdateTargetId = "tableBody", InsertionMode= InsertionMode.Replace,
Url = Url.Action("GetPeopleData") //确保javascript enable和disable时能正常显示
};
}
<h2>
GetPeople</h2>
<table>
<thead>
<tr>
<th>
First
</th>
<th>
Last
</th>
<th>
Role
</th>
</tr>
</thead>
<tbody id = "tableBody">
@Html.Action("GetPeopleData", new { selectedRole = Model })
</tbody>
</table>
@using(Ajax.BeginForm(ajaxOpts))
{
<div>
@Html.DropDownList("selectedRole", new SelectList(
new[] { "All" }.Concat(Enum.GetNames(typeof(Role)))))
<button type="submit">
Submit</button>
</div>
}
<div>
@foreach (string role in Enum.GetNames(typeof(Role)))
{
<div class="ajaxLink">
@Ajax.ActionLink(role, "GetPeople",
new { selectedRole = role },
new AjaxOptions
{
UpdateTargetId = "tableBody",
Url = Url.Action("GetPeopleData", new { selectedRole = role })
})
</div>
}
</div>