Home ascx working, cshtml not: content controls
Reply: 0

ascx working, cshtml not: content controls

user1396
1#
user1396 Published in June 20, 2018, 1:33 am

This is the ascx:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<NavigationEntryViewModel>>" %>
<%@ Import Namespace="WebShop.Models.ViewModels"  %>

<%  if(Model.Count() > 0){ %>
    <ul class="navigation">
        <%  foreach(NavigationEntryViewModel entry in Model)
            {
                Html.RenderPartial("Entry", entry);
            }
        %>   
    </ul> 
<%  } %>

And this is the new cshtml:

@using WebShop.Models.ViewModels

@model List<NavigationEntryViewModel>

@if(Model.Count() > 0)
{
    <ul class="navigation">
        @foreach(NavigationEntryViewModel entry in Model)
        {
            Html.RenderPartial("Entry", entry);
        }        
    </ul>
}

Running the project with ascx is fine, but when I run it with the cshtml I get the error

content controls are allowed only in content page that references a master page

I tried to set the Layout to null, that didn´t work. I tried to comment Html.RenderPartial, that didn´t work too.

The View is invoked by

return View("Show", entries);

where entries is a list of NavigationEntryViewModel.

I´m lost, can somone please help?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314067 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO