【问题标题】:How to use dynamic model to partial view in mvc?如何使用动态模型在 mvc 中进行局部视图?
【发布时间】:2014-01-07 11:54:38
【问题描述】:

有一次我需要返回 IndexParty 模型。接下来我需要将 IndexPerson 模型返回到视图。

 public Tuple<IndexParty> GetTuple(){
     var tuple = new Tuple<IndexParty>(model);
     return tuple;
 } 

我的 .cshtml 类在这里

@model Mymodel

<div class="hide partial-view" id="partyrelationship">
    @Html.Partial("../Party/Index", Mymodel)
</div>

然后我想加载为部分视图。我该怎么做?

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-partialview


    【解决方案1】:

    您只需要一个带有返回此模型的 Index 操作的 PartyController.cs(从 Controller 继承)。

    派对控制器:

    public ActionResult Index()
    {
        return PartialView(GetTuple());
    }
    

    【讨论】:

      【解决方案2】:
      @model dynamic
      
      <div class="hide partial-view" id="partyrelationship">
          @Html.Partial("../Party/Index", Model)
      </div>
      

      我也会将你的部分移动到它自己的控制器动作而不是使用索引动作。

      【讨论】:

      猜你喜欢
      • 2019-07-20
      • 2021-07-16
      • 2010-12-06
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 2021-03-15
      • 2016-06-09
      相关资源
      最近更新 更多