2
在Details視圖中,我想從其他表格顯示一個網格。如何更好地實施它?我試圖做一個這樣的方式(錯誤:無法隱式轉換類型「無效」到「對象」):如何將參數傳遞給ASP.NET MVC中的部分視圖?
<%= Html.RenderPartial("~/Views/Appartament/Index.ascx", new { id = Model.blockhouse_id })%>
下面是詳細代碼視圖:
<%@ 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控制器的代碼:
public ActionResult Index(int blockhouse_id)
{
var _appartament = apt.GetBlockAppartaments(blockhouse_id).ToList();
return View("Index", _appartament);
}
有definitly東西你的代碼錯誤,我認爲你是錯把視圖和控制器。你的任務聽起來微不足道,但我認爲你做錯了。看看http://asp.net/mvc/ –