4

I have the following problem:

Razor syntax shows errors on view and won't autocomplete in most cases, for example:

@model someModel // The name 'model' does not exist in the current context

@Html.EditorFor(m=>m.SomeProp) // System.Web.WebPages.Html.HtmlHelper does not contain a defenition for 'EditorFor'.... same for .Partial and  .OtherExtensions

//This do work:
@Html.CheckBox //.DropDown .Encode .Hidden ect... (The non extended properties of html)

What I've tried to far based on similar SO topics:

  1. Make sure I have the same webpages / mvc version on the web.config in the main dir. and in the Views dir.

  2. Unload the project, delete the .user file, reload project (that helped once though)

  3. Rebuild/ clean/ delete the bin files

This is driving me crazy, please help!

added: Using Webpages 3.0.3XXX and MVC 5.2.3XXX

added #2: It seems it happen because the Views directory was separated to another project - don't do it! use the views in the same project as your mvc controllers.

Ziv Weissman
  • 4,400
  • 3
  • 28
  • 61
  • 1
    Did you happen to upgrade to MVC 5 from an older version? If yes, an all inclusive search of the previous version number (like System.Web.Mvc 4.0.0.0) will help. I thought I had every .config file checked too, but there were some residual stuff. – Hari Hara Chandan Aug 03 '15 at 07:25
  • Tnx, I've searched entire solution for web.system.mvc and webpages, it is all 5.2.3.0 and 3.0.0, I did not upgrade from 4, it was a new project MVC5 – Ziv Weissman Aug 03 '15 at 07:29
  • @ZivWeissman Did you try adding namespace by `@using` on top of view? – User3250 May 31 '17 at 06:56
  • @User3250 tnx for your input, yes I've tried with the using. – Ziv Weissman May 31 '17 at 15:01
  • Nothing seems to have worked since an year :) – User3250 May 31 '17 at 15:05
  • @User3250 yes I gave up on this, I think I know the reason, not the solution though - It was due to separation of MVC controllers and Views on another project. – Ziv Weissman May 31 '17 at 15:06
  • question 1 - is it only in this view or all views? question 2 - If you look at ~/Views/web.config, do you have the following namespace listed: `System.Web.Mvc.Html`? The web.config in the Views folder will import this namespace for all views under the Views folder. See the `` element in this question as an example: https://stackoverflow.com/questions/29810936/views-web-config-and-its-content – ps2goat May 31 '17 at 15:16
  • I didn't realize this was a year old :) – ps2goat May 31 '17 at 15:18

1 Answers1

0

The MVC architecture always looks for views in the following folders

~/Views/ControllerName/ActionName.[cshtml|vbhtml|aspx|ascx]

OR

~/Views/Shared/ActionName.[cshtml|vbhtml|aspx|ascx]

Secondly, you can specify where to look for as per this article. Though never tried it myself.

athar13
  • 382
  • 1
  • 8