tags:

views:

219

answers:

3

Hi! I am trying to create a new strong-typed view for an MVC project.

I tried to create it both from the Controller class (right click -> add View) or directly from the Views (right click -> Add view) and selected it to be a strong-typed view. From the drop-down, I selected the Model and data class it should refer to.

While filling in the content of my View, I need to declare it as:

<p>
   Title:
   <%= Html.Encode(Model.Title) %>
</p>

For some reason, I just get this error: "The name 'Model' does not exist in the current context".

I must be missing something out... :-(
Any comment or idea would be great!

+1  A: 

Does your code behind class inherit from ViewPage<ModelType>?

Joel Potter
What I get as a default when creating the View is:Inherits="Project.Views.Locations.Details"I tried to change it to:Inherits="Project.Views.Locations.Details<Project.Models.Location>"I'm not sure if this would be correct... (it didn't work though)
Right click on the aspx page and select "View Code". At the class definition you should have something like: public class Details : ViewPage<Location>
Joel Potter
+1  A: 

It should be <%= Html.Encode(ViewData.Model.Title) %>

seanlinmt
they added the Model property on a view around rc1.
AndreasN
A: 

I had a similar problem when adding MVC Views to an existing WebForms application. I resolved it by adding a Web.config file to the Views folder, copying the contents from another MVC project.

Pat James