Using ASP.NET MVC From Visual Web Developer Express 2008 April 19, 2008
Posted by kevinbe71 in ASP.NET, Development, MVC, Web Development.Tags: ASP.NET MVC
2 comments
Recently I’ve been curious about Microsoft’s ASP.NET MVC framework that is currently at “Preview 2″ stage (although there may be more recent CTPs floating around). I’ve read a bit about it and felt it was time to actually dig in and start writing a web site that uses the technology. I don’t own a copy of VS 2008 so I figured I’d download VWD Express 2008 and play around with it. Well, the problem is that ASP.NET MVC doesn’t specifically support it. Fortunately, I found a blog posting by Jason Whitehorn that got me started. However, I couldn’t get it working immediately. I ran into two issues that I’ll explain below. I figure that this may be helpful to others.
Jason Whitehorn’s blog posting here:
http://jason.whitehorn.ws/CommentView.aspx?guid=…
Jason provides all the pieces of the puzzle but his page is missing a few minor points that a newbie may run into:
- Downloading the zipped template to the Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer folder doesn’t appear to work at first if you download the C# template. The reason for this is that VWD defaults to VB as a language. All you need to do is select C# from the drop-down list and the template will appear. Another mistake a newbie might make is to unzip this file. Don’t- it won’t be found if it isn’t zipped.
- You should change the VirtualPath property of your web site from “/<your_web_site_name>” to just “/”. Otherwise you’ll need to build routes that include your web site name as the first part of the URL- not preferable. If you don’t do this you may end up with the error shown below.
The RouteData must contain an item named ‘controller’ with a non-empty string value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The RouteData must contain an item named ‘controller’ with a non-empty string value.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The RouteData must contain an item named 'controller' with a non-empty string value.]
System.Web.Mvc.RouteData.GetRequiredString(String keyName) +201
System.Web.Mvc.MvcHandler.ProcessRequest(IHttpContext httpContext) +139
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +55
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.
ProcessRequest(HttpContext httpContext) +28
System.Web.CallHandlerExecutionStep.System.Web.
HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Anyway, I hope this will be helpful to someone else who encounters this error. Jason’s blog post isn’t accepting comments so I couldn’t post this “answer” there.