1

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"

11
  • 1
    It needs to be capital M - Html.RenderPartial("...", Model.g) And your Index() method should return View(), not PartialView() Commented Oct 11, 2015 at 0:24
  • 1
    Where is the NullReferenceError? On model.g and model.t the intellisense underline of model? Can you try using Model instead of model? Edit: Welp Stephen's online, might as well go to bed! His solution will work Commented Oct 11, 2015 at 0:24
  • @StephenMuecke: I still have errors...Compiler Error Message: CS1061: 'System.Collections.Generic.IEnumerable<BOL.HomeMultipleBinder>' does not contain a definition for 'g' and no extension method 'g' accepting a first argument of type 'System.Collections.Generic.IEnumerable<BOL.HomeMultipleBinder>' could be found (are you missing a using directive or an assembly reference?) Commented Oct 11, 2015 at 0:36
  • There is nothing in the code you have shown which would cause that. Indicate which line of code throws that error. And indicate the names of each of the views you have shown. And you need to include the code, not images of it. Commented Oct 11, 2015 at 0:41
  • 1
    @Guzzyman, Nowhere in the code you have shown are you passing IEnumerable<BOL.HomeMultipleBinder>' to a view. All you have shown is the Index() method which passes a single instance of HomeMultipleBinder so you have not shown us the correct code. Commented Oct 11, 2015 at 0:51

1 Answer 1

0

I don't think you are able to write this in your views:

@Html.DisplayNameFor(model => model.content)

your model type is IEnumerable

Is not it giving any errer!!?

this might help

Sign up to request clarification or add additional context in comments.

1 Comment

This has been resolved by Stephen Muecke in a private chat. I simply removed the sign before the Html.RenderPartial("_gameView",Model.g); in my question above and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.