代码:
<% using (Ajax.BeginForm("GetResourcesByProject", "CreateRequest", new AjaxOptions { UpdateTargetId = "ResourceListDiv"}))
{
Response.Write(Html.DropDownList("SelectProject", Model.ProjectList, "Select Project", new { onchange = "this.form.submit();" }));
} %>
当我运行页面时,我得到了正确的控制器操作,以使用表单集合中的正确数据触发:
public ActionResult GetResourcesByProject(FormCollection formCollection)
{
var resourceModels = (from project in POTSModel.ProjectList
where project.Id == Convert.ToInt32(formCollection["SelectProject"])
select project).First().Resources;
return PartialView("ResourceList", resourceModels);
}
它在 Ajax.ActionLink 中运行良好,如下所示:
<%= Ajax.ActionLink("Select", "GetResourcesByProject", "CreateRequest", new { projectId = item.Id }, new AjaxOptions { UpdateTargetId = "ResourceListDiv" })%>
当帖子发生时,我会导航到一个新页面,而不是停留在现有页面上并更新 div 的内容。
谢谢。