0

Trying to convert a partialview to to a List as well as pass in a variable, but I can't seem to get it to pass the variable. Included a snippet below, thanks for the help.

Here's what I want to do (but with a partial view, not an iframe.

<iframe src="/Episodes/Grid?seriesId=@Html.DisplayFor(model => model.SeriesID)"></iframe>

And here's how I'm trying to do it, but I can't get it to do both the conversion to a List and passing in the SeriesID variable at once.

@{
    Html.RenderPartial("~/Views/Episodes/Grid.cshtml", new List<myA.Models.Episodes> { new myA.Models.Episodes() };  new { SeriesID = Model.SeriesID }););
}

As per adiga's suggestion, I created another model but I'm getting Internal server errors, see below.

Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace myA.Models
{
    public class Combined
    {
        public IEnumerable<myA.Models.Episodes> Episodes { get; set; }
        public string SeriesID { get; set; }
    }
}

but I get

'IEnumerable<Episodes>' does not contain a definition for 'Number' and no extension method 'Number' accepting a first argument of type 'IEnumerable<Episodes>' could be found (are you missing a using directive or an assembly reference?)
  • Possible duplicate of [How to pass parameters to a partial view in ASP.NET MVC?](https://stackoverflow.com/questions/6549541/how-to-pass-parameters-to-a-partial-view-in-asp-net-mvc) – adiga Oct 09 '17 at 15:58
  • Okay, I created a new model called Combined with the episodes List and SeriesID. But I'm getting lots of "'IEnumerable' does not contain a definition for 'Number' and no extension method 'Number' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?)" errors? –  Oct 09 '17 at 16:11
  • int, it's spamming that for every column in the db table –  Oct 09 '17 at 18:29

1 Answers1

0

Solved my issue by inserting the required partial view using JQuery. So I didn't have to convert to a IEnum List and pass in the parameter as I passed it in using JQuery .load, similar idea to the iframe I originally posted but kinda cleaner.

<script>$('#episode-list').load('/Episodes/Grid?SeriesID=' + @Html.DisplayFor(model => model.SeriesID));</script>