I have 2 strongly typed partial views to be displayed in a strongly typed view. I used the repository pattern.
Here's the code to parent model
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; }
}
}
Here're s the controller:
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);
}
}
}
and here's the view:
@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);
}
and below are the respective partial views:
@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>
and
@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>
I have the following Compiler Error "Message: CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments"