Asp.Net Mvc: cannot access model namespace from my view

So, I have a ViewModel in the "models" folder of my Mvc project with the namespace "Web.Models" (My Mvc project is called "Web"). I think it is worth noting that I have 3 more projects in my solution: Domain, Test and Tasks. Representation models are assigned properties from classes in my Domain.Entities folder. I can create a new instance of my viewmodel in my controller when I add a namespace in my controller.

using Web.Models; 

However, when I create a view, it cannot import the namespace. This actually prompts me to add a namespace via "alt + enter" or "ctrl + dot", and it still says that it cannot resolve the object.

 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Web.Models.MyViewModel>" %> 

I also tried adding a global namespace reference in my Web.config, but with no luck. Any suggestions?

+6
c # namespaces asp.net-mvc-2
source share
3 answers

You can add it to your web.config under system.web/pages/namespaces . For example.

 ... <namespaces> ... <add namespace="Web.Models"/> </namespaces> ... 
+8
source share

Compile the application first, and then make sure MyViewModel is public.

+1
source share

I found out that this is related to my build of ReSharper, I upgraded to 5.1 and made sure that, as I think, it was a kind of "cache error".

+1
source share

All Articles