ASP.NET MVC - Add View: View Data Class

R

RichB

When working with and ASP.NET MVC application, I have selected to Add a View
for return as part of a controller class method. Within the dialogue is a
"Create a strongly-typed view" checkbox and selection of a view data class.

What classes are populated to the view data class dropdown?


I ask as I have created an application (similar to nerddinners.com) and have
created a Linq to SQL class for Events, and another for Venues. In this case
the list contains the Events class, but not the Venue.

Any advice on why this might be occurring?

Thanks, Richard
 
R

RichB

I would still like to understand what is happening here, however the list
now appears to be populating correctly. I Created a view and manually
changed
Inherits="System.Web.Mvc.ViewPage"

to
Inherits="System.Web.Mvc.ViewPage<EventsManager.Models.Venue>" %>

immediately after doing this the drop down was populated with all of the
classes related to my Venues Linq to Sql class.

Can anyone explain this?

Thanks,
Richard
 
S

Steven Cheng

Hi Richard,

As for the MVC page's "Add strong-typed view", the drop down should be able
to list all the existing public model classes(such as LINQ generated one or
other custom classes) in the same project. One thing worth notice is that
when you add some new classes(LINQ class or custom class), it may not be
precompiled by the IDE yet so that the MVC dropdown may still haven't been
able to find them. You can try "save all files in the project" and perform
a "rebuild" on the entire project to make sure all those classes got
precompiled.

I've also had a test on my side. When I add a custom class into the MVC
project and try create a strong-typed view, the dropdown doesn't list my
class, after perform a rebuild the class appears.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).


--------------------
 
S

Steven Cheng

Hi Richard,

Just some additional updates on this. After some debugging against the VS
IDE(with MVC web project), I found that the MVC controller's "AddView"
dialog will query available model classes via the following method:

Microsoft.VisualStudio.Web.Mvc.MvcAddViewDialog.GetTypes

and Microsoft.VisualStudio.Web.Mvc.MvcAddViewDialog type is defined in the
following assembly(installed with MVC project template):

Microsoft.VisualStudio.Web.Extensions, Version=9.0.0.0

which resides in the C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE folder. You can have a look at the code there for the
codelogic VS uses to get available model types.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
R

RichB

Thanks Steven,


Makes absolute sense now. I think that when I added the view manually I ran
the app to check it which obviously built it, solving the problem.

I've tested this now and all is fine, I'll have a look at the GetTypes code
when I get chance.

Thanks,
Richard
 
S

Steven Cheng

Thanks for your followup Richard,

I'm glad that you've also figured out it. If you have interests, you can
use reflector to inspect the assembly/class I mentioned which contains the
visual studio design-time code for the "AddViewDialog".

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).



--------------------
<ueuDRd#[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top