-1

I am trying to pass a model to my partial class in asp.net however it keeps giving me the following error: stack trace

I tried calling the partial class the following ways:

 <section id="categoryPartial">
    @*1*@   @Html.Partial("_CategoryPartial", new EindopdrServer.Models.Category())
    @*2*@   @Html.Partial("_CategoryPartial", new EindopdrServer.Models.Category{ Name => Model.Name })
    @*3*@   @Html.RenderPartial("_CategoryPartial", new EindopdrServer.Models.Category { Name => Model.Name })
 </section>

My partial class:

@model IEnumerable<EindopdrServer.Models.Category>

<table>
    <tr>
       @if(Model != null){
            @foreach (var item in Model) {    
                <td class="categoryPartial">
                    <a href="Products/SearchIndex?productGenre=@item.Name"><b>@Html.DisplayFor(modelItem => item.Name)</b></a>
                </td>    
            }
        }
    </tr>
</table>

Any solutions?

After removing the @ and if statement: enter image description here

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Arnout
  • 157
  • 1
  • 13

1 Answers1

3

Because the if-statement is code, and not markup, the foreach is already considered code. You don't need to have @ before it.

So, simply remove the @ character before the foreach

Andy T
  • 10,223
  • 5
  • 53
  • 95