views:

38

answers:

3

So I have a ViewModel in the 'models' folder of my Mvc project with a namespace of 'Web.Models' (My Mvc project is called 'Web') I think its worth mentioning I have 3 other projects in my solution: Domain, Test, and Tasks. The view model is assigned properties from classes in my Domain.Entities folder. I can create a new instance of my viewmodel in my controller when I add the namespace in my contoller.

using Web.Models;

When I create the view however, it cant seem to import the namepace. It actually prompts me to add the namespace via 'alt+ enter' or 'ctrl + dot' and it still says that it cant resolve the object.

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

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

A: 

First, compile your app, then make sure that MyViewModel is public.

Clicktricity
Been compiled several time and is public.
Justin Soliz
It 'should' work. Try adding an explicit include statement in the view itself: <%@ Import Namespace="Web.Models" %>
Clicktricity
I've tried that as well. I have 4 projects in the solution, I'm wondering if I'm missing something in that regard.
Justin Soliz
Is the view in a different project to the models? Have you added the project reference between projects? (clutching at straws now!)
Clicktricity
I know its strange.... the really weird thing is the class is available in the controller but not in the view. I can get it to work, I've changed the namespace to system.web.mvc as well as moving it over to my domain project and changing the namespace to domain.models. I guess its just more of an annoyance at this point (and really strange, never happened to me before).
Justin Soliz
+1  A: 

You can add it in your web.config under system.web/pages/namespaces. E.g.,

...
<namespaces>
    ...
    <add namespace="Web.Models"/>
</namespaces>
...
RedFilter
Thats what I was referring to when I created a "Global" namespace, but it is added in my namespaces of my Web.confing
Justin Soliz
A: 

Found out it had to do with my build of ReSharper, I updated to 5.1 and it took care of what I guess was some sort of a "cache bug".

Justin Soliz