这是我的控制器动作看起来像更新的WebGrid在下拉列表回传asp.net的MVC
[HttpPost]
[OutputCache(Location = OutputCacheLocation.None)]
public ActionResult GetData(string Key, string Physician)
{
string physicianCode = Physician.Split(' ').ElementAt(0).Trim();
CaseProfile caseProfile = HttpContext.Cache.Get(Key) as CaseProfile;
return PartialView("_CaseProfile", caseProfile);
}
这是我在这里面jQuery的对话框中显示我的部分观点_CaseProfile
<div id="paged-case-profile-div">
@using (Ajax.BeginForm("GetData", "Group",
new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "paged-case-profile-div"
, OnSuccess="OnSuccess", OnComplete="OnComplete", InsertionMode=InsertionMode.Replace }))
{
@Html.HiddenFor(m => m.Key)
@Html.DropDownList("Physician", Model.PhysicianSelectList,
new { style = "font-size: 11px;", onchange = "this.form.submit();" })
<div>
@{
var grid = new WebGrid(source: Model.Items.AsEnumerable(),
canPage: true, canSort: false, rowsPerPage: 10);
}
@grid.GetHtml(
htmlAttributes: new { align = "center" },
tableStyle: "table",
headerStyle: "header-row",
alternatingRowStyle: "alternate-row",
columns:
physicianGrid.Columns(
physicianGrid.Column("PatientId", "Patient Id"),
physicianGrid.Column("MedRecNum", "Med Rec Num"),
physicianGrid.Column("AdmissionDate", "Admission Date")))
</div>
}
</div>
我所有的js文件都添加到_Layout.cshtml文件中。 我想要做回ajax回落在下拉列表中,并用控制器操作返回的最新内容更新paged-case-profile-div。 问题是,从服务器返回的新内容被渲染到不是我想要的新页面。我只想让我的div在ajax表单之外更新为新内容。 请注意,我只是在OnSuccess和OnComplete javascript方法上显示警告框。 您能否让我知道我的代码中有什么问题?
另外 - 请注意,我已经检查了几乎所有关于此stackoverflow的相关问题,但他们都没有帮助我。如果有人能指出我代码中的错误,并给我建议改正它而不是指向其他问题/发布,我将不胜感激。
它已经在我的_Layout.cshtml页面。而我的所有其他对话框有一个Ajax形式工作正常,问题只是这部分。 – user979189 2012-03-28 16:01:27
@ user979189,好的,我已经用另一个建议更新了我的答案。 – 2012-03-28 16:13:43
太棒了!它像一个魅力。 – user979189 2012-03-28 16:19:29