我正在重写帖子以使其更清晰
我有一个具有以下操作的HomeController
public ActionResult About()
{
MapDetailsRepository repMapDetail = new MapDetailsRepository("name=ge");
YearRepository repYear = new YearRepository("name=ge");
SuperMapModel smM = new SuperMapModel();
smM.saVM = new StudentAssessmentViewModel();
MapDetailResultSet mapDetailResultSet = repMapDetail.GetMapDetails(53);
smM.saVM.mapDetails = mapDetailResultSet.mapDetails.ToList();
smM.saVM.results = mapDetailResultSet.results.ToList();
smM.saVM.students = mapDetailResultSet.students.ToList();
smM.scM = new SearchControlViewModel();
smM.scM.YearList = new SelectList(repYear.GetAll(), "yearID", "year");
return View(smM); }
public ActionResult DisplaySearchResults(string searchText) {
MapDetailsRepository repMapDetail = new MapDetailsRepository("name=ge");
SuperMapModel smM = new SuperMapModel();
smM.saVM = new StudentAssessmentViewModel();
MapDetailResultSet mapDetailResultSet = repMapDetail.GetMapDetails(22);
smM.saVM.mapDetails = mapDetailResultSet.mapDetails.ToList();
smM.saVM.results = mapDetailResultSet.results.ToList();
smM.saVM.students = mapDetailResultSet.students.ToList();
return PartialView("~/Views/Maps/_MapDetailsList.cshtml", smM.saVM);
}
SuperMapModel是具有2个视图模型的超类-scM用于搜索面板部分控制-saVM用于MapDetailList部分控制
在页面上加载SuperMapModel传递给View,该View将各自的模型传递给每个部分控件
@Html.Partial("_SearchPanel", Model.scM)
@Html.Partial("~/Views/Maps/_MapDetailsList.cshtml", Model.saVM)
我的MapDetails部分控制非常复杂,因此我提供了一个简化的版本
@foreach(ShortStudent geStudent in Model.students)
{
@geStudent.firstnameforeach (run it x number of times)
{
@foreach (ShortResult geResult in Model.results)
{
if (geResult.ResultValue != null)
{
}
}
}
}
setResultValue函数在主视图(关于)上定义,它设置当前td的innerhtml
function setResultValue(colIndex, rowIndex, resultValue) {
alert("inside about");
var cell = $("#MapDetails").children().children()[rowIndex].children[colIndex];
cell.innerHTML = resultValue;
}
PS此网格将转换为document.ready上的剑道网格。
现在,它可以完美地在页面加载中工作,但是当我从searchpanel内部单击搜索按钮时,我会执行以下操作(在searchpanel部分控件上定义)
function refreshGrid() {
alert("search panel");
var url = '@Url.Action("DisplaySearchResults", "Home")';
$("#MapDetails").load(url, { searchText: "Lee" }, function () {
alert("success");
});
}
PS这里的回叫从不触发
所以现在我只将部分视图与 DisplaySearchResults中*的新数据绑定*
现在很明显,它在主页上找不到脚本函数setResultValue,因此我在局部视图mapdetailslist上复制了相同的脚本函数setResultValue(这当然是一种不好的做法)
更新
调试后,我得到了更多详细信息,所以现在页面加载时出现了新问题,我可以得到$(“#MapDetails”)。children()。children()[rowIndex],但单击按钮后未定义