Tag Archives: asp.net MVC

Using the ASP.NET MVC framework with Visual Web Developer Express

If you try to use the new ASP.NET MVC framework with Visual Web Developer Express, there are some manual steps you have to take in order to get up and running.

Select “New Web Site” and pick “ASP.NET 3.5 Extensions Web Site”.

The example web.config I saw added the following lines in the “system.web”/”pages” section. But I’m not sure if they are necessary. I just added them as a cargo cult programming convention at this point.

                <add namespace="System.Web.Mvc"/>
                <add namespace="System.Linq"/>

edit to add: The namespaces element defines a set of namespaces to be imported in every page and serves the same function as the @Import attribute on an aspx page.

You have to create your “Models” and “Controllers” folder in the “App_Code” folder.

You have to manually add global.asax to the site and manually add the default routes. Add this to the “Application_Start” method.

            // Note: Change Url= to Url="[controller].mvc/[action]/[id]" to enable
            //       automatic support on IIS6

            RouteTable.Routes.Add(new Route {
                Url = "[controller]/[action]/[id]",
                Defaults = new { action = "Index", id = (string)null },
                RouteHandler = typeof(MvcRouteHandler)

When adding a new view, make sure it inherits from “ViewPage” not “System.Web.UI.Page”

Remove any content from Default.aspx in the root of the site. It’s just a placeholder to route IIS to the MVC framework.

Add the “using System.Web.Mvc;” line to any MVC page (e.g. Controllers, Views, Model, etc…)

Otherwise the standard MVC framework rules apply.

Phil Haacked will correct me if I missed anything, but following those directions I was able to bring up my default “Index” view and display some text.