Jason Whitehorn

MarshalByRefObject.net
posts - 48, comments - 26, trackbacks - 6

My Links

News

Archives

Post Categories

.NET

Java

Proud Member Of...

XNA

Using ASP.NET MVC From Visual Web Developer Express 2008

UPDATE (12/17/2007): My blog has moved. This post is now located at: http://jason.whitehorn.ws/2007/12/10/Using-ASPNET-MVC-From-Visual-Web-Developer-Express-2008.aspx




Today marked the released of the first preview of MVC for ASP.NET. While it works just fine from the free Visual Web Developer Express 2008, this release is missing a project template to help you get up an running quickly.

So, I have thrown together a project template to allow you get get starting using MVC from VWD Express. Unlike VWD Express' big brother, VWD Express seems unable to create Web Application, only Web Sites. So this template has a slightly modified layout from the one available from Visual Studio.

Image Hosted by ImageShack.us

Since Web Site projects can only arbitrarily host classes in the App_Code directory, I have placed the Models and Controllers there. The Views are located in an appropriately named directory off of the site root.

There are two versions of this template, one for C# and one for VB.NET.

  • ASP.NET MVC Web Site For C#
  • ASP.NET MVC Web Site For VB.NET

    Download the template of your choice to the Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer directory located in your "My Documents" directory. After doing so, simply start VWD Express and you will notice a new template available when you go to create a new web site.

    Image Hosted by ImageShack.us

    This was just something that I threw together really quickly, and is not intended to be a demonstration of MVC. It is simply a starting point for getting started quickly with MVC. If you should encounter any difficulties with this, please let me know.
  • Print | posted on Monday, December 10, 2007 7:35 PM | Filed Under [ ASP.NET ]

    Feedback

    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    great. thanks for the effort.
    12/11/2007 8:57 AM | justin kadima
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    The zip file should be in the \My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer folder
    12/11/2007 9:35 AM | justin kadima
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    Justin,

    I appreciate the kind words. I'm glad the template was useful for you.

    You are correct, the template path listed in the post was incorrect. I have updated the post with the path you specific.

    Thanks again,
    Jason Whitehorn
    12/11/2007 5:44 PM | Jason Whitehorn
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    Hey, thanks! I was going to do this last night, but then was too tired ... now I don't have to.

    Cheers,
    Travis
    12/11/2007 7:03 PM | Travis
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    HI, Thx for the post with the MVC template.
    I copied the MVC Template, Connected to a <myservername>\SQLEXPRESS server. Then I copied the Contoller, Views and Models directoties into the Solotion Explorer of MVC website. So far so good.
    Then I tried a built, but encountered a problem with the includes because of the application name MVCapplication5 that is in example code from ScottGu.
    In the WebDeveloper you get a website, not an application... There must be an easy solution. Can you help me?

    Gr. Hans
    12/16/2007 1:55 PM | Hans
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    Hans,

    You are correct, the examples that Scott Guthrie (ScottGu) has been posting are using web applications (not web sites), and thusly will not work in Visual Web Developer Express without modification.

    The template I have provided here works with VWD Express by placing the models and controllers in the App_Code directory. Worth noting, is that the views must NOT be placed in the App_Code directory, they need to reside outside of it so that they are compiled in the same fashion as normal ASPX resources.

    So, when you were porting Scott's examples to a web site, from a web application, if you had placed either of those items in the wrong location the compiler would not have been able to correctly assembly your site.

    Also worth looking at is the web.config and the global.asax. Both of those files have special items for the sake of MVC. However, the global.asax and web.config's from Scott's web application should work without modification in a web site.

    I hope this helped explain some of the key differences in how an MVC site is constructed for a web site versus a web application.

    Thanks,
    Jason Whitehorn
    12/16/2007 2:09 PM | Jason Whitehorn
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    Hi Jason,

    I still get 4 error message on
    Error 1 Could not load type 'Views.Layouts.Site'. C:\Documents and Settings\hansm\Mijn documenten\Visual Studio 2008\WebSites\ASP.NET MVC Web Site1\Views\Shared\Site.Master 1
    Error 2 Could not load type 'Views.Home.Index'. C:\Documents and Settings\hansm\Mijn documenten\Visual Studio 2008\WebSites\ASP.NET MVC Web Site1\Views\Home\Index.aspx 1
    Error 3 Could not load type 'Views.Layouts.Site'. C:\Documents and Settings\hansm\Mijn documenten\Visual Studio 2008\WebSites\ASP.NET MVC Web Site1\Views\Shared\Site.Master 1
    Error 4 Could not load type 'Views.Home.About'. C:\Documents and Settings\hansm\Mijn documenten\Visual Studio 2008\WebSites\ASP.NET MVC Web Site1\Views\Home\About.aspx 1

    I can explain Error 1 and 3, because the Layout are missing completely in the code from Scott
    I cannot explain Errors 2 and 4. In de Index.ASPX files I have:
    Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Views.Home.Index" %>

    In the codebehind
    using System;
    using System.Web;
    using System.Web.Mvc;

    namespace Views.Home
    {
    public partial class Index : ViewPage
    {
    }
    }
    Regards, Hans
    12/16/2007 3:38 PM | Hans
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    Hi Jason,

    Thanks for the project template! It has saved a lot of time for me to get up and running with MVC framework.

    Regards,
    Abhishek
    1/8/2008 12:51 AM | Abhishek
    Gravatar

    # re: Using ASP.NET MVC From Visual Web Developer Express 2008

    Thanx a lot from me too!

    That's been useful.
    1/10/2008 4:48 AM | jaims
    Comments have been closed on this topic.

    Powered by: