gpt4 book ai didi

asp.net-mvc - C# MVC4 部分 View 与 Controller 中的其他 ActionResult

转载 作者:行者123 更新时间:2023-12-05 01:03:26 24 4
gpt4 key购买 nike

我有个问题。
我有我的 Controller “DashboardNB2Controller”,我的 View “index.cshtml”,我想在我的“index.cshtml”中集成一个名为“_PartialView.cshtml”的局部 View 。两个 View 都在同一个文件夹中。在我的 Controller 中,我的局部 View 中有一个数据库操作的“ActionResult _PartialView”。

但是如果我将局部 View 集成到索引 View 中,则操作结果“_PartialView”不起作用。我没有结果。对我的数据库的查询是正确的。我检查了这个。

这是我的代码

  • 我的 Controller 与部分 View 的 ActionResult
    public ActionResult _PartialView()
    {
    var lastMessages= (from t in db.view_tbl_message
    orderby t.Date descending
    select t).Take(10);



    ViewModelDashboard model = new ViewModelDashboard();
    model.view_tbl_message = lastMessages.ToList();


    return PartialView("_PartialView", model);

    }

  • 我的 index.cshtml
     @model AisWebController.Areas.Statistics.Models.ViewModelDashboard


    @{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";

    }

    <br />
    @{Html.Action("_PartialView", "DashboardNB2");}

    <br />

    还有我的 _PartialView.cshtml
     @model WebApplication.Areas.Stats.Models.ViewModelDashboard

    <table class="table table-bordered">
    <tr>
    <th>
    Date
    </th>
    <th>
    User
    </th>
    <th>
    Message
    </th>

    </tr>
    @foreach (var item in Model.view_tbl_message)
    {

    <tr>
    <td>
    @Html.DisplayFor(modelItem => item.Date
    </td>
    <td>
    @Html.DisplayFor(modelItem => item.User)
    </td>
    <td>
    @Html.DisplayFor(modelItem => item.Message)
    </td>

    </tr>


    }
    </table>

    如果有人可以提供帮助-那就太棒了!

    最佳答案

    改变

     @{Html.Action("_PartialView", "DashboardNB2");}


     @Html.Action("_PartialView", "DashboardNB2")

    关于asp.net-mvc - C# MVC4 部分 View 与 Controller 中的其他 ActionResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24697035/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com