我有两个强类型的部分视图要在强类型视图中显示。我使用了存储库模式。
这是父模型的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BOL
{
public class HomeMultipleBinder
{
public IEnumerable<game> g { get; set; }
public IEnumerable<team> t { get; set; }
}
}
这里是控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BOL;
namespace TeamBuildingCompetition.Areas.Common.Controllers
{
public class gHomeController : BaseCommonController
{
// GET: Common/gHome
public ActionResult Index()
{
var model = new HomeMultipleBinder();
model.g = objBs.gameBs.GetALL();
model.t = objBs.teamBs.GetALL();
return View(model);
}
}
}
以及以下观点:
@model BOL.HomeMultipleBinder
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout_new.cshtml";
}
<h2>Index</h2>
@{
@Html.RenderPartial("_gameView",Model.g);
@Html.RenderPartial("_teamView",Model.t);
}
及以下是各自的部分观点:
@model IEnumerable<BOL.game>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.gameName)
</th>
<th>
@Html.DisplayNameFor(model => model.description)
</th>
<th>
@Html.DisplayNameFor(model => model.content)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.gameName)
</td>
<td>
@Html.DisplayFor(modelItem => item.description)
</td>
<td>
@Html.DisplayFor(modelItem => item.content)
</td>
</tr>
}
</table>
和
@model IEnumerable<BOL.team>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.teamName)
</th>
<th>
@Html.DisplayNameFor(model => model.teamPicture)
</th>
<th>
@Html.DisplayNameFor(model => model.description)
</th>
<th>
@Html.DisplayNameFor(model => model.content)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.teamName)
</td>
<td>
@Html.DisplayFor(modelItem => item.teamPicture)
</td>
<td>
@Html.DisplayFor(modelItem => item.description)
</td>
<td>
@Html.DisplayFor(modelItem => item.content)
</td>
</tr>
}
</table>
我有以下编译器错误&#34;消息:CS1502:最佳重载方法匹配&#39; System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)&#39;有一些无效的参数&#34;
答案 0 :(得分:0)
我认为你不能在你的观点中写下这个:
@Html.DisplayNameFor(model => model.content)
您的模型类型是IEnumerable
是不是给了任何错误!!?