MVC 5部分视图中加载不同的页面

问题描述 投票:0回答:1

概述:

我基本上是建立一个单一的网页应用程序。三个输入和该加载有基于输入数据的两个表。

每个表被设定成标签,每个标签都有一个按钮来加载它们各自的表中的数据。一个表中的局部视图设置。我想这一点,看看它是否工作,所以我可以两个表的设置为一个局部视图。

问题:局部视图加载表到一个新的窗口,当我点击提交按钮。

例如:那么,在加载Web应用程序,例如,“http://localhost:30000/CommissionDatas/”索引页面加载页面和空表就好了。

我使用一个ViewModel,因为每个表使用不同的模型,我将获得有关具有不同的数据模型的局部视图表的错误。

当我点击按钮“gpmbutton”,为局部视图表中,buttion使用“formmethod”属性调用的ActionResult方法“_TrueUp”,它会检索数据和数据模型返回局部视图。但是,局部视图的表,它的数据结束了张贴到“http://localhost:30000/CommissionDatas/_TrueUp”,这是一个完全新的一页。

我已经试图改变的ActionResult方法类型PartialViewResult并更改返回类型“PartialView()”在控制器中的“查看”,并且仍然没有奏效。我已经使用@Partial在索引页以及@RenderPartial的局部视图也试过,我也得到了相同的结果。

此外,无论是“索引”和“TrueUp”局部视图页面是在视图文件夹下的“委员会数据”同一个文件夹。

请帮忙!

附:我删除,因为数据是敏感的,是不是这个问题所必需的代码。

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>

This is the Partial View

_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>
    }

This is the Controller.

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);

 }
c# razor asp.net-mvc-5 viewmodel partial-views
1个回答
-1
投票

请尝试@ Html.Action( “yourAction”, “yourController”)而不是@ Html.RenderPartial( “_ TrueUp”)。

欲了解更多信息,请访问:How can I use Html.Action? MSDN

编辑:

用途:@ Html.Partial( “partialViewName”,partialViewModel)partialViewModel是可选的。 你的情况:@ Html.Partial( “_ TrueUp”)。

© www.soinside.com 2019 - 2024. All rights reserved.