-6ren">
gpt4 book ai didi

asp.net - 如何在 ASP.NET MVC 中向 Partial View 传递参数?

转载 作者:行者123 更新时间:2023-12-02 12:28:59 25 4
gpt4 key购买 nike

在“详细信息” View 上,我想显示其他表中的网格。如何更好地实现?我试图以这样的方式做到这一点(错误:无法将类型“void”隐式转换为“对象”):

<%= Html.RenderPartial("~/Views/Appartament/Index.ascx", new { id  = Model.blockhouse_id })%>

这是详细信息 View 中的代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<testMVC.Models.Blockhouse>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Details</h2>

<p>
blockhouse_id:
<%= Html.Encode(Model.blockhouse_id) %>
</p>
<p>
name:
<%= Html.Encode(Model.name) %>
</p>

<p>
Appartaments:
<%= Html.RenderPartial("~/Views/Appartament/Index.ascx", new { id = Model.blockhouse_id })%>
</p>

</asp:Content>

以及Index.ascx Controller 的代码:

public ActionResult Index(int blockhouse_id)
{
var _appartament = apt.GetBlockAppartaments(blockhouse_id).ToList();
return View("Index", _appartament);
}

最佳答案

RenderPartial 没有返回值。

而不是

<%= %>

使用

<% %>

至于 Razor,而不是

@

使用

@{ }

关于asp.net - 如何在 ASP.NET MVC 中向 Partial View 传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1988358/

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