2

I am using Microsoft MVC and C#. I have a usercontrol (example.ascx) created and at the top I'm inheriting System.Web.MVC.ViewUserControl<PostTransferViewModel>

Now, while my model name is appended to ViewUserControl, I get "The name 'Model' does not exist in the current context" and "The name 'Html' does not exist in the current context. If I removed the <PostTransferViewModel> from the end of ViewUserControl then everything works fine, but I need <PostTransferViewModel>.

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

<div class="postTransferTank">
    <h2>
        Approved Post Transfers</h2>
    <% if (Model.ApprovedPostTransfers.Count() == 0)
       { %>
    <span class="emptyList">There are currently no approved Post Transfers for this tank.</span><br />
    <% } %>
    <% else
        { %>
    <%=Html.DisplayFor(x => x.ApprovedPostTransfers,"PostTransferList") %>
    <% } %>
    <br />
    <%=Html.ActionLink<PostTransferController>(x => x.NewPostTransfer(), "Enter Post Transfer", new { @class = "create-link" })%>
    <br />
    <% if (Model.DraftPostTransfers.Count() != 0)
       { %>
    <h2>
        Draft Post Transfers</h2>
    <%=Html.DisplayFor(x => x.DraftPostTransfers, "PostTransferList") %>
    <% } %>
</div>
Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
J.B.
  • 268
  • 1
  • 5
  • 15
  • just want to check, does this control live inside a project that has a reference to System.Web.Mvc – Dave Archer Feb 24 '10 at 13:37
  • Yes, which makes things even more strange. What's funny is I have other usercontrols that reference other models in the "Inherits" line and I don't get this error. Guess I could have mentioned that. – J.B. Feb 24 '10 at 13:39
  • Is it a runtime error or just an autocompletion or "while editing" problem? – Dave Archer Feb 24 '10 at 13:48
  • It is an autocompletion "while editing" problem. – J.B. Feb 24 '10 at 13:52
  • ok, you could try cleaning the solution and rebuilding. Also, do you use code-behind? or rather, was a code-behind auto generated? – Dave Archer Feb 24 '10 at 13:56
  • After cleaning and building the red "squigglies" went away and came back a few seconds later. While hovering over the 'Model.' or the 'Html.' I'm offered options to help bind the item. For Model I'm giving the option to bind it to 'StructureMap.Query.Model' and for 'Html' I'm given the options 'xVal.Html' and 'System.Web.Mvc.Html'. – J.B. Feb 24 '10 at 14:17
  • Have you imported either or both of those in your web.config, or in the file that holds PostTransferViewModel. It might be confusing things, in which case you'd probably have to do something like this.ViewData.Model... – Dave Archer Feb 24 '10 at 14:23
  • 4
    Problem fixed! So here's what happened. Because our project is so large, we wanted to have even better organization than MS MVC already offers. Instead of using the default Model, View, and Controller folders that the project automatically creates, we modularized the different apps we have in the project and gave each app its own Model View and Controller folders to better organize things. The one thing I forgot to add to my specific app's Views folder was a web.config file and thus my problem all along. I greatly appreciate your help David! – J.B. Feb 24 '10 at 14:34

3 Answers3

5

This forum post has a potential solution to your problem:

Sometimes Intellisense doesn't show up in aspx/ascx/master files if there is a compilation error in the application. If you try running the site and you get a compilation error from ASP.NET, try fixing it and then see if it works.

If the app was previously using ASP.NET MVC Beta and you later changed it to use the fully released version then it's also quite likely that there's a configuration problem. Try comparing the two web.config files in the project (one in the root and one in the Views folder) and see if there are any differences between them.

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Dave Archer
  • 3,022
  • 20
  • 23
3

I had the same problem...

In my web.config file I had just the regular namespaces placed in the node...

    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />

Once I added this to my node the error went away...

pages validateRequest="false"
    pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <controls>
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
  </controls>

I hope this helps someone out. I was stuck for a couple of hours trying to figure this out.

friism
  • 19,068
  • 5
  • 80
  • 116
SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195
-2
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0" />
  </parameters>
</defaultConnectionFactory>

Solution for this problem