[英]MVC 5 PartialVIew is loading in Different Page
概述:
我实质上是在构建一个单页应用程序。 三个输入和两个基于输入数据加载的表。
每个表都设置为一个选项卡,每个选项卡都有一个按钮以加载各自表的数据。 在局部视图中设置了一个表。 我正在尝试这样做,看看是否可行,因此我可以将两个表都设置为局部视图。
问题:当我单击提交按钮时,partialview正在将表加载到新窗口中。
示例:因此,在加载Web应用程序(例如,“ http:// localhost:30000 / CommissionDatas / ”)后,索引页面将加载该页面,而空白表就可以了。
我使用的是ViewModel,因为每个表使用不同的模型,并且我会收到有关具有不同数据模型的Partial视图表的错误。
单击部分视图表的按钮“ gpmbutton”后,按钮将使用“ formmethod”属性调用actionresult方法“ _TrueUp”,它将检索数据并将数据模型返回到部分视图。 但是,部分视图的表及其数据最终发布到“ http:// localhost:30000 / CommissionDatas / _TrueUp ”,这是一个全新的页面。
我已经尝试将actionresult方法类型更改为PartialViewResult并将返回类型从“ PartialView()”更改为控制器中的“视图”,但仍然无法正常工作。 我也尝试过在索引页面中使用@Partial以及对部分视图使用@RenderPartial,并且得到相同的结果。
同样,“索引”和“ _TrueUp” PartialView页面都位于views文件夹中“ CommissionDatas”下的同一文件夹中。
请帮忙!
PS我删除了对问题不重要的代码,因为数据很敏感。
Index.cshtml
-------------------------------------------------------------
@model CommissionReport.Models.ViewModels.CommissionViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="submit" ID="commissionbutton"
formaction="ReturnCommissionData"
formmethod="post"
/>
@if (Model != null)
{
<table id="mainTable" class="ui striped selectable table">
<thead>
<tr>
</tr>
</thead>
<tbody>
@foreach (var item in Model.CommissionData)
{
<tr>
</tr>
}
</tbody>
</table>
}
<input type="submit" class="btn btn-primary" ID="gpmbutton"
formaction="_TrueUp" formmethod="post"
/>
<div>
@if (Model != null)
{
Html.RenderPartial("_TrueUp");
}
</div>
</body>
</html>
_TrueUp.cshtml
----------------------------------------------------------------------------
@model CommissionReport.Models.ViewModels.CommissionViewModel
@{
Layout = null;
var trueupmodel = Model.TrueUp;
}
@if (Model != null)
{
<table id="mainTable" class="ui striped selectable table">
<thead>
<tr>
</tr>
</thead>
<tbody>
@foreach (var item in Model.TrueUp)
{
<tr>
</tr>
}
</tbody>
</table>
}
private CommissionViewModel vm = new CommissionViewModel();
[HttpPost]
public ActionResult ReturnCommissionData(FormReturn form)
{
//Code to return data here
vm.CommissionData = db.CommissionDatas.ToList();
return View("Index", vm);
}
<HttpPost>
public ActionResult _TrueUp(FormReturn form)
{
//Code For Data to be returned here
vm.TrueUp = model;
return PartialView("_TrueUp", vm);
}
请尝试@ Html.Action(“ yourAction”,“ yourController”)而不是@ Html.RenderPartial(“ _ TrueUp”)。
有关更多信息,请访问: 如何使用Html.Action? MSDN
编辑:
使用:@ Html.Partial(“ partialViewName”,partialViewModel)partialViewModel是可选的。
在您的情况下:@ Html.Partial(“ _ TrueUp”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.