我有一个类SuperMapModel
public class SuperMapModel
{
public StudentAssessmentViewModel saVM { get; set; }
public SearchControlViewModel scM { get; set; }
}
在我的页面 About.cshtml 标记是
@model SuperMapModel
<div>
@Html.Partial("_SearchPanel", Model.scM)
</div>
<div class="row">
<div class="col-md-12 table-responsive" id="mapsDiv">
@Html.Partial("~/Views/Maps/_MapDetailsList.cshtml", Model.saVM)
</div>
从我的HomeController我设置上述属性并返回模型如下
public ActionResult About()
{
SuperMapModel smM = new SuperMapModel();
smM.scM = new SearchControlViewModel();
smM.scM.x = ..
smM.scM.y = ..
smM.saVM = new StudentAssessmentViewModel();
smM.saVM.x = ..
smM.saVM..y = ..
smM.saVM..z = ..
return View(smM);
}
现在,当页面重新加载时,我只通过 ajax 刷新页面中的部分视图 _MapDetailsList.cshtml。所以我在 MapsController 中调用了另一个函数(来自 javascript),它的作用与上面几乎相同
public ActionResult DisplaySearchResults(int mapHeaderId, int yearId, string classIds, int indicatorGroup, string indicatorIds)
{
SuperMapModel smM = new SuperMapModel();
smM.saVM = new StudentAssessmentViewModel();
smM.saVM.x = ..
smM.saVM..y = ..
smM.saVM..z = ..
return PartialView("~/Views/Maps/_MapDetailsList.cshtml", smM.saVM);
}
是否可以从 About() 内部调用 DisplaySearchResults 以进行重构?
编写第三个方法并从其他方法中调用它。
void PopulateStudentAssessmentViewModel(SuperMapModel smM) {
smM.saVM = new StudentAssessmentViewModel();
smM.saVM.x = ..
smM.saVM..y = ..
smM.saVM..z = ..
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句