0

I have a _layout page that has a viewmodel and razor declaration like below

@using System.Globalization
@using Mvc4WebRole.Models
@model HomeViewModel

and a section on this page @sidebar using this HomeViewModel

After this codes some of my views are using other ViewModels like ProductDetailView below

@model Mvc4WebRole.Models.PrdcDetailViewModel

However I want to rebuild the project while redirected ProductDetailView it is giving me an error about ViewModel requirements like this:

enter image description here

Is there any reason? I have researched this error but they all telling me that you shouldnt be use IEnumerable declaration when needed uniq entity. This is not my case.

2
  • @tereško please try to fix more than just the asp.net-mvc tag. Commented Jan 5, 2015 at 10:20
  • 1
    Remove the @model declaration from your _layout.cshtml and only use it in your strongly typed views. Commented Jan 5, 2015 at 10:21

2 Answers 2

1

You should not strongly type your layout page.

Remove @model HomeViewMode from your _layout.cshtml file.

The only place where you should bind model to your views is in your view files. If your side bar uses this model, render it as a partial view, which can use its own model.

After you have removed the HomeviewModel from your layout, you might need to add it to the views which use it, but do not have this line yet.

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

1 Comment

Thanks Serv yes i need it for the sidebar content, i will try to use partial view
1

The _layout.cshtml file is kind of a "Master page", not a view, so you should not have a model declared. Everything that is dynamic, should be put in views, and if you need something dynamic in the _layout view, you should use ViewBag or some simular object/container.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.