Using statements being required in Razor views

In all the builds this week (currently using 2144) I'm being prompted by ReSharper to use a using statement in a Razor view in order to resolve objects.  Using statements are not required by MVC in these cases.

Matt

6 comments

Please, provide more details or sample solution.

0

A good example is the @model declaration.  I have a model of type say DomainModel.Person in a web application called WebApp.  DomainModel is a reference in WebApp.  My @model declaration will be

@model Person

The EAP is telling me that I need to add a using statement for DomainModel.Person even though MVC does not require that using statement..

This has been an issue that was crept into many versions of the EAP before and been resolved (I reported it once a few months ago).

Matt

0

As I uderstand just reference project is not enough for resolving classes inside it in Razor.
You still need to import namespaces or throug web.config or explicitly in page.
So, if you can send small repro-case it will help as I still don't see what's wrong in ReSharper.

0

I am getting this too,

1. Create a new project MVC 3 Razor Internet application
2. Goto Views\Account\Register.cshtml, remove the namespace for the model - prompt appears as expected
3. Goto Views\Web.config, add namespace for Models to system.web.webPages.razor\pages\namespaces
4. Go back to Views\Account\Register.cshtml, prompt should be gone

attached solution



Attachment(s):
ReSharperRazorViewsError.zip
0

Fixed in May 4 nightly build.

0

Good job!
It is working in the 4 May build

ta, Ant

0

Please sign in to leave a comment.