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.
所以我在我的Mvc项目的'models'文件夹中有一个ViewModel,其命名空间为'Web.Models'(我的Mvc项目叫做'Web')我认为值得一提的是我在我的解决方案中有3个其他项目:Domain,测试和任务。视图模型从我的Domain.Entities文件夹中的类分配属性。当我在控制器中添加命名空间时,我可以在控制器中创建我的viewmodel的新实例。
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.
但是,当我创建视图时,它似乎无法导入名称空间。它实际上提示我通过'alt + enter'或'ctrl + dot'添加命名空间,它仍然说它无法解析对象。
<%@ 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?
我也尝试在我的Web.config中添加对命名空间的全局引用,但没有运气。有什么建议?
3 个解决方案
#1
9
You can add it in your web.config under system.web/pages/namespaces
. E.g.,
您可以在system.web / pages / namespaces下的web.config中添加它。例如。,
...
<namespaces>
...
<add namespace="Web.Models"/>
</namespaces>
...
#2
1
First, compile your app, then make sure that MyViewModel is public.
首先,编译您的应用程序,然后确保MyViewModel是公共的。
#3
1
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".
发现它与我的ReSharper构建有关,我更新到5.1并且它处理了我认为是某种“缓存错误”。
#1
9
You can add it in your web.config under system.web/pages/namespaces
. E.g.,
您可以在system.web / pages / namespaces下的web.config中添加它。例如。,
...
<namespaces>
...
<add namespace="Web.Models"/>
</namespaces>
...
#2
1
First, compile your app, then make sure that MyViewModel is public.
首先,编译您的应用程序,然后确保MyViewModel是公共的。
#3
1
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".
发现它与我的ReSharper构建有关,我更新到5.1并且它处理了我认为是某种“缓存错误”。