Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net Mvc: Cannot access my models namespace from my view

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?

like image 364
Justin Soliz Avatar asked Sep 09 '10 20:09

Justin Soliz


1 Answers

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

...
<namespaces>
    ...
    <add namespace="Web.Models"/>
</namespaces>
...
like image 71
D'Arcy Rittich Avatar answered Sep 28 '22 10:09

D'Arcy Rittich