开发者

Why can't I access my viewmodel in my user control?

I've tried this in a couple different ways:

1:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyNameSpace.MyModel>" %>

2:

<%@ Import Namespace="MyNameSpace.MyModel" %>

But no matter what I do, I don't have access to开发者_开发知识库 this.Model or anything else I'd expect to see. Other controls and pages in the project are able to access these, and none of the developers are able to tell me why theirs can and my can't. Any ideas?

EDIT

I've created a few controls and pages since then. Sometimes, intellisense finds this.Model with no problem. It also finds things like Html.RenderPartial() and various other goodies that it's supposed to find. So, for those of you who would tell me that intellisense doesn't work in views, you're wrong. IT DOES. But it's not consistent amongst all views. As far as I and any other developers can tell, I'm not doing anything different. Things I've tried:

  • Close the solution
  • Delete post build folders
  • Reopen solution
  • Rebuild, either regular or analysis build

Sometimes those steps fix the problem, but for some controls, I just can't make the red squiggley lines go away! It's not the end of the world, since it doesn't produce runtime errors, but I want to understand what's going on here. Surely somebody has experienced this and has learned the source of the problem.


You can also try adding it to the web.config :

  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="MyHtmlHelperLibrary.HtmlExtensions"/>
    <add namespace="MyOtherNamespace"/>
  </namespaces>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜