[英]MVC Partial View render as a view after a post
美好的一天,我有一个索引页面,在 2 个选项卡上显示 2 个部分视图。 每个选项卡上都有一个提交按钮,当单击提交按钮时,它会点击控制器,控制器会执行一些处理并返回该局部视图的填充模型,但局部视图本身会呈现为视图。
Index.chtml
页面
...
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3" style="float:left">
<div >
<ul id="myTab" class="nav nav-tabs nav-stacked">
<li class="active">
<a href="#IdentifyPerson" data-toggle="tab" class=""><strong>Identify Person</strong></a>
</li>
<li>
<a href="#PersonInformation" data-toggle="tab" class=""><strong>Person Information</strong></a>
</li>
</ul>
</div>
</div>
<div class="tab-content col-lg-9 col-md-9 col-sm-9 col-xs-9">
<div id="IdentifyPerson" class="tab-pane fade in active">
@Html.Partial("IdentifyPerson")
</div>
<div id="PersonInformation" class="tab-pane fade">
@Html.Partial("PersonInformation")
</div>
</div>
HomeCntroller.cs
页面
[AuthorizeUser]
public ActionResult Index(string ActionValue)
{
return View();
}
[HttpGet]
[AuthorizeUser]
public ActionResult IdentifyPerson()
{
return View();
}
[HttpPost]
[AuthorizeUser]
public ActionResult IdentifyPerson(ViewModel_IdentifyPerson model)
{
// do populate model
return View(model);
}
关于解决这个问题的任何建议?
您可能正在使用Form而不是ajax form 。 所以你需要使用 ajax 表单来保持在同一页面上。
在识别人选项卡中
@using (Ajax.BeginForm("IdentifyPerson", "Home", null, new AjaxOptions { UpdateTargetId = "IdentifyPerson" , InsertionMode= InsertionMode.Replace}))
{
//Other stuff
<input type="submit" value="Save" />
}
和个人信息选项卡
@using (Ajax.BeginForm("IdentifyPerson", "Home", null, new AjaxOptions { UpdateTargetId = "PersonInformation", InsertionMode = InsertionMode.Replace }))
{
//Other stuff
<input type="submit" value="Save" />
}
您需要在您的视图中包含此 Js 文件<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
并将您的返回类型PartialView
更改为 in action
[HttpPost]
[AuthorizeUser]
public ActionResult IdentifyPerson(ViewModel_IdentifyPerson model)
{
// do populate model
return PartialView(model);
}
如果您使用引导程序,您可以简单地将您的表单包装在引导程序模式窗口中作为局部视图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.