Menew February 2016

partial view c# mvc

which folder should my partial view be so that it can recognize @model?

I have a main index page, once a person searches for a keyword, I have a viewmodel that filters the DB results and pass it to the partial view below:

Below is my partialview.cshtml for my search results under the "Shared" folder.

@model Namespace.ViewModels.ItemViewModel //<-------------this is not been recognized, @model does not exist in the current context 
@if (Model.SearchResults.Count == 0)
{
    <h3 class="text-error">No items matched your search query!</h3>
}
else
{
    foreach (var result in Model.NewsList)
    {
        // display search results
    }
}

Answers


Eric J. February 2016

You are most likely working on an MVC4 or earlier project using Visual Studio 2015. Unfortunately, VS2015 does not provide correct parsing for pre-MVC5 projects and falsely reports this as an error.

The page will still work at runtime.

The only solutions that I am aware of are to use an earlier version of Visual Studio or upgrade the project to MVC5.

Post Status

Asked in February 2016
Viewed 3,865 times
Voted 9
Answered 1 times

Search




Leave an answer