Experiencing ASP.NET MVC – Day 1

  1. Install
    I installed ASPNet Extension Preview before VS2008, so when I opened up VS2008, I didn’t see new project type named with ‘ASP.NET 3.5 MVC Web Application’. Had to re-install to make those new items appear.
    Entity Framework is also needed, don’t know why.
  2. Linq
    Following ScottGu’s instructions Part 1, used a Linq to ADO to SQL class. IT IS REALLY COOL! I like the graphic view of dbml file. Looked into the source, it works like a wrapper for ActiveRecord, and the most important thing is, it can support stored procedure so easily.
  3. MS Unit Test
    The default MVC web application comes with a test project using ‘Microsoft.VisualStudio.TestTools.UnitTesting’, ScottGu didn’t give his implementation of TestViewEngine which many people are asking for.
    Fortunately, I found an example of TestViewEngine from JAK’s blog whose idea is from Phil Haack’s Rhino mock solution.
    I could not make Haack’s test code work in MSUnitTest, so I commented out mocks.VerifyAll, and added assert code after. All the test case turned to green then. Woohoo!
  4. ActionLink
    This is pretty similar to robyOnrails, but I was having problem to make this happen

    <%= Html.ActionLink(c.CategoryName, new { action=”List”, category =c.CategoryName}) %>

    unless I changed category to id, also, the controller action list(string category) needs to change to List(int id).
    I don’t know how could Scott change this default id parameter to customized category, until I run into SocttGu’s blog part 2, URL routing. By adding

                RouteTable.Routes.Add(new Route
    Url = “Products/List/[category]”,
    Defaults = new { controller = “Products”, action = “List”, category = (string)null },
    RouteHandler = typeof(MvcRouteHandler)

    in front of default routing:

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

    Everything works just good as ScottGu’s example.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s