ASP.NET MVC Preview 3 Release

This morning we released the Preview 3 build of the ASP.NET MVC framework.  I blogged details last month about an interim source release we did that included many of the changes with this Preview 3 release.  Today's build includes some additional features not in last month's drop, some nice enhancements/refinements, as well as Visual Studio tool integration and documentation.

You can download an integrated ASP.NET MVC Preview 3 setup package here.  You can also optionally download the ASP.NET MVC Preview 3 framework source code and framework unit tests here.

Controller Action Method Changes

ASP.NET MVC Preview 3 includes the MVC Controller changes we first discussed and previewed with the April MVC source release, along with some additional tweaks and adjustments. 

You can continue to write controller action methods that return void and encapsulate all of their logic within the action method.  For example:

which would render the below HTML when run:

Preview 3 also now supports using an approach where you return an "ActionResult" object that indicates the result of the action method, and enables deferred execution of it.  This allows much easier unit testing of actions (without requiring the need to mock anything).  It also enables much cleaner composition and overall execution control flow.

For example, we could use LINQ to SQL within our Browse action method to retrieve a sequence of Product objects from our database and indicate that we want to render a View of them.  The code below will cause three pieces of "ViewData" to be passed to the view - "Title" and "CategoryName" string values, and a strongly typed sequence of products (passed as the ViewData.Model object):

One advantage of using the above ActionResult approach is that it makes unit testing Controller actions really easy (no mocking required).  Below is a unit test that verifies the behavior of our Browse action method above:

 

We can then author a "Browse" ViewPage within the \Views\Products sub-directory to render a response using the ViewData populated by our Browse action:

When we hit the /Products/Browse/Beverages URL we'll then get an HTML response like below (with the three usages of ViewData circled in red):

Note that in addition to support a "ViewResult" response (for indicating that a View should be rendered), ASP.NET MVC Preview 3 also adds support for returning "JsonResult" (for AJAX JSON serialization scenarios), "ContentResult" (for streaming content without a View), as well as HttpRedirect and RedirectToAction/Route results.  

The overall ActionResult approach is extensible (allowing you to create your own result types), and overtime you'll see us add several more built-in result types.

Improved HTML Helper Methods

The HTML helper methods have been updated with ASP.NET MVC Preview 3.  In addition to a bunch of bug fixes, they also include a number of nice usability improvements.

Automatic Value Lookup

With previous preview releases you needed to always explicitly pass in the value to render when calling the Html helpers.  For example: to include a value within a <input type="text" value="some value"/> element you would write:

The above code continues to work - although now you can also just write:

The HTML helpers will now by default check both the ViewData dictionary and any Model object passed to the view for a ProductName key or property value to use.

SelectList and MultiSelectList ViewModels

New SelectList and MultiSelectList View-Model classes are now included that provide a cleaner way to populate HTML dropdowns and multi-select listboxes (and manage things like current selection, etc).  One approach that can make form scenarios cleaner is to instantiate and setup these View-Model objects in a controller action, and then pass them in the ViewData dictionary to the View to format/render. 

For example, below I'm creating a SelectList view-model class over the set of unique category objects in our database.  I'm indicating that I want to use the "CategoryID" property as the value of each item in the list, and the "CategoryName" as the display text.  I'm also setting the list selection to the current CategoryId of the Product we are editing:

Within our view we then just have to write the below code to indicate that we want to create a drop-downlist against the SelectList we put into ViewData:

This will then render the appropriate drop down with items and selection for us at runtime:

 

Built-in error validation support isn't included with our HTML helpers yet (you currently need to write code for this) - but will show up in the future, which will make form editing scenarios even easier.

You'll also start to see ASP.NET AJAX helper methods show up in future preview releases as well, which will make it easier to integrate AJAX into MVC applications with a minimum of code.

URL Routing Improvements

ASP.NET MVC Preview 3 includes a number of improvements to the URL routing system.  URL routing is one of the most "fundamental" components of a web MVC framework to get right, hence the reason we've spent a lot of focus the first few previews getting this area nailed.  Our new URL routing engine will ship in .NET 3.5 SP1 this summer, and will support both Web Forms and MVC requests.  ASP.NET MVC will be able to use the built-in .NET 3.5 SP1 routing engine when running on .NET 3.5 SP1. ASP.NET MVC will also include its own copy of the assembly so that it can also work on non-SP1 systems.

Some of the URL Routing Improvements in the Preview 3 release include:

MapRoute() and IgnoreRoute() helper methods

ASP.NET MVC Preview 3 includes new "MapRoute" and "IgnoreRoute" helper methods that you can use to more easily register routing rules.  MapRoute() provides an easy way to add a new MVC Route rule to the Routes collection.  IgnoreRoute() provides an easy way to tell the URL routing system to stop processing certain URL patterns (for example: handler .axd resources in ASP.NET that are used to serve up JavaScript, images, etc). 

Below is an example of the default RegisterRoutes() method within Global.asax when you create a new ASP.NET MVC project where you can see both of these new helper methods in action. 

The MapRoute() helper method is overloaded and takes two, three or four parameters (route name, URL syntax, URL parameter default, and optional URL parameter regular expression constraints). 

You can call MapRoute() as many times as you want to register multiple named routes in the system.  For example, in addition to the default convention rule, we could add a "Products-Browse" named routing rule like below:

We can then refer to this "Products-Browse" rule explicitly within our Controllers and Views when we want to generate a URL to it.  For example, we could use the Html.RouteLink view helper to indicate that we want to link to our "Products-Browse" route and pass it a "Food" category parameter using code in our view template like below:

This view helper would then access the routing system and output an appropriate HTML hyperlink URL like below (note: how it did automatic parameter substitution of the category parameter into the URL using the route rule):

We could alternatively use the new Url.RouteUrl(routeName, values) within views if we wanted to just retrieve the URL for a named route (and not output the <a> html element). 

We could also use the new RedirectToRoute(routeName, values) helper method on the Controller base class to issues browser redirects based on named routing rules. 

Richer URL Route Mapping Features

ASP.NET MVC Preview 3 also supports a bunch of new URL route mapping features.  You can now include "-", ".", ";" or any other characters you want as part of your route rules.

For example, using a "-" separator you can now parse the language and locale values from your URLs separately using a rule like below:

This would pass appropriate "language", "locale", and "category" parameters to a ProductsController.Browse action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
{language}-{locale}/products/browse/{category} /en-us/products/browse/food language=en, locale=us, category=food
  /en-uk/products/browse/food language=en, locale=uk, category=food

Or you can use the "." file extension type at the end of a URL to determine whether to render back the result in either a XML or HTML format:

This would pass both "category" and a "format" parameters to the ProductsController.Browse action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
products/browse/{category}.{format} /products/browse/food.xml category=food, format=xml
  /products/browse/food.html category=food, format=html

ASP.NET MVC Preview 3 also supports wildcard route rules (these were also in Preview 2).  For example, you can indicate in a rule to pass all remaining URI content on as a named parameter to an action method:

This would pass a "contentUrl" parameter to the WikiController.DisplayPage action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
Wiki/Pages/{*contentUrl} /Wiki/Pages/People/Scott contentUrl="People/Scott"
  /Wiki/Pages/Countries/UK contentUrl="Countries/UK"

These wildcard routes are very useful to look at if you are building a blogging, wiki, cms or other content based system.

Summary

Today's Preview 3 release of ASP.NET MVC includes a bunch of improvements and refinements.  We are starting to feel good about the URL routing and Controller/Action programming model of MVC, and feel that those areas are starting to bake really well.  In future preview releases you'll start to see more improvements higher-up the programming model stack in areas like Views (html helpers, validation helpers, etc), AJAX, sub-controllers and site composition, deeper Login, Authentication, Authorization and Caching integration, as well as data scaffolding support. 

I also have a (very) long tutorial post that I started putting together this past weekend that walks-through building an application using ASP.NET MVC Preview 3 that I'm hoping to wrap up and post in the next few days.  This should provide both a good intro to ASP.NET MVC, as well as help provide some context on how all the pieces fit together if you are interested in using the ASP.NET MVC option.

Hope this helps,

Scott

125 Comments

  • Slightly off topic question, but what color scheme are you using in VS? Can you provide a download link for it?

  • Instead of a single ActionResult why not have a "List" property on Controller. This allows multiple actions to be queued easily. For example: SetStatusCode, WriteCookie, RenderPage
    The action methods can return void once more. You can provide methods in Controller that add actions to the list e.g. RenderView(data). There could also be a general "DoAction" method.
    Testing is still easy since a test can inspect the contents of the action list.
    In addition, you can have (via extension methods) tests like:
    Assert.That(homeController.DidRenderView("homepage"));

  • That is great! I look forward to using the new Preview. Do you know when Scott Hanselman's updated screen casts for Preview 3 will be on the ASP.NET MVC website?

  • Delllliiicious!!! Can't wait the ASP.NET MVC to be released. I invest a lot to my team developing using all the Preview releases of MVC Framework but I'd be in total happiness to invest even more when all risks of breaking changes are gone.
    Thanks for your work!

  • Nice, JSON support is really kicking ass.

  • This is looking really good. I like what has been happening with routing.

  • Hey Scott,

    Quick question of unit testing controller actions without mocking. Can you describe how you would test actions that except POST data? For example, an Authenticate action that accepts a username and password.

    Congrats on the release!

    Jim

  • Yes! None to soon. I have a couple of projects I have been holding off on starting; have been waiting for this release.
    Thanks again!

  • Why are the form controls not strongly typed? I feel like something like Html.TextBox(model=>model.FieldName); should be possible. Or maybe something with the form...
    <% using(MvcForm form=Html.Form(ViewData.MyData)) { %>
    m.FieldName) %>

  • Hello,

    Url Routing replace Url Rewritter?

  • Great Post!! How do you manage to write so well.

    I really appreciate your work.

    Thanks,
    RN

  • Hi Scott! Going forward, would ASP.NET MVC also support the ability to use an RIA front-end like Silverlight with MVC? If an RIA front-end was used as the View, how could we pass ViewData from the Controller to it?

  • I'm looking forward to how you end up implementing the Html Form Validation Helpers, as this is an area I am still unsure on how to implement properly without the ASP.NET Form PostBack/ViewState safety net. But that won't be for another release, do you have a timeframe for release 4, and will the Validation Helpers be part of it?

  • Just found out about asp.net mvc today. Looks really cool. It seems like it's based alot on Rails, is this true?

  • So how does this relese play with SP1?

  • Nice work, gotta say I’m loving this so far.

    One question: In preview 2 you couldn’t overload action methods, will this change?

    E.g. You can’t do this:

    public ActionResult ShowProducts(int category) {...}

    public ActionResult ShowProducts(int category, int subCategory) {...}

    public ActionResult ShowProducts(int category, int subcategory, int someOtherFieldToFilterOn) {...}

    Should I be using the most expressive method and just making each param nullable?

  • Does it play well with the SP1 Beta?

  • Thanks Scott.

    It's really great to see (and use) the MVC framework as it evolves - muchas gracias!

  • Has this version support VWD express 2008?

  • This is looking really good - I like the testable changes to the Action Result.
    Question... I may be off track a bit but is there an easy way for me (in a unit test for example) to test the "view output" *given* a set of view data. e.g. I create some known view data such as page title, product list etc and push that into the view render engine giving me a string (what is ultimately sent to the browser). I then want to be able to perform asserts etc on the string to look for certain data (or the absense of it).
    Even better, in the designer having the same pricipal for the preview mode saving the whole cycle of building/running the site to check changes to the rendered view.

  • Hi Andrew,

    >>>>>> Instead of a single ActionResult why not have a "List" property on Controller. This allows multiple actions to be queued easily. For example: SetStatusCode, WriteCookie, RenderPage The action methods can return void once more. You can provide methods in Controller that add actions to the list e.g. RenderView(data). There could also be a general "DoAction" method.

    It is an interesting idea, and one we looked at a little. A couple of the nice things about the return approach, though, are that it allows chaining of filters and actions - for example, one filter could intercept the result, change/transform it (or replace it), and then pass it along. It makes execution control flow a easier to read (since you can return from anywhere). And in the future it will make async execution (where you yield the worker thread) as well as sub-controllers easier to build.

    There are actually a number of popular MVC frameworks out there (including Django and Tapestry) that use this approach - so it is also a pretty proven pattern.

    The good news, though, is that the ASP.NET MVC framework is extensible - so if you prefer a void approach using a List to track results you can implement one without too much effort, and re-use everything else in ASP.NET MVC.

    Hope this helps,

    Scott

  • Hi Elijah,

    >>>>>>> That is great! I look forward to using the new Preview. Do you know when Scott Hanselman's updated screen casts for Preview 3 will be on the ASP.NET MVC website?

    I saw that Scott just posted some new videos earlier today: http://www.hanselman.com/blog/ASPNETMVCPreview3.aspx

    Enjoy!

    Scott

  • Scott,

    Very good!!! I am always on my blog disclosed the news of ASP.NET MVC here in Brazil.
    Great job of the whole team!

    Bra zillll... zilll... zill... zil

    :)

    []´s

  • Guru Gu wins again!

    thanks heaps to all the people working on ASP.NET MVC! We all just can't get enough of it and appreciate everything you guys and gals are doing.

    3 Cheers and can't wait for more.

    now, to update my existing sites :)

  • This is the best release yet! I believe that was genius from you to give a job to Phil to work in open source. I wonder what is Haak coing to work next! I am guessing in another open source? May I ask for a micro blogging engine? ;-)

    Cheers
    Al
    http://geotwitter.net

  • Hi Jim,

    >>>>>>> Quick question of unit testing controller actions without mocking. Can you describe how you would test actions that except POST data? For example, an Authenticate action that accepts a username and password.

    There are a couple of ways you could handle this. If it is a form post scenario where you are submitting a username/password, you could just handle these as arguments to the action method. For example:

    public object Login(string username, string password)
    {
    // check for login here...
    }

    You wouldn't need to-do anything special to test this scenario (just pass the parameters directly).

    Now, in my scenarios you might want to work with the Request or Response objects directly within your action method. In scenarios like this you'll want to "Mock" a fake request/response object that you set on the Controller. You can do this with ASP.NET MVC because the request/response intrinsics it uses are interface based and allow test implementation to be assigned.

    Hope this helps,

    Scott

  • Hi Joseph,

    >>>>>>> Why are the form controls not strongly typed? I feel like something like Html.TextBox(model=>model.FieldName); should be possible. Or maybe something with the form...

    Some of the form controls (like the form element) support strongly-typed generics/lambda based usage. We don't have a strongly typed TextBox and others just yet (although in theory they could be built). Mainly this is because Html.TextBox("ProductName") often seems conceptually simpler than Html.TextBox(product, p=>p.ProductName)

    Thanks,

    Scott

  • Hi Anthony,

    >>>>>> Url Routing replace Url Rewritter?

    URL Routing is a little different than the URL Rewritter class (and is much, much richer). In the Url rewriter scenario you are taking one URL and transforming it into another that is ultimately executed. With URL routing you skip this transform step and instead route a URL directly to code to run. This can sometimes make it easier to control the URLs you want.

    Hope this helps,

    Scott

  • Hi EricTN,

    >>>>>>> Hi Scott! Going forward, would ASP.NET MVC also support the ability to use an RIA front-end like Silverlight with MVC? If an RIA front-end was used as the View, how could we pass ViewData from the Controller to it?

    This is a scenario we are thinking about. Starting with today's Preview 3 release we do have the ability to return JSON based objects to a client. Silverlight clients could use this to retrieve and send data back and forth to Controller classes on the server.

    Hope this helps,

    Scott

  • Hi Dominic,

    >>>>>>> I'm looking forward to how you end up implementing the Html Form Validation Helpers, as this is an area I am still unsure on how to implement properly without the ASP.NET Form PostBack/ViewState safety net. But that won't be for another release, do you have a timeframe for release 4, and will the Validation Helpers be part of it?

    Hopefully the validation helpers will show up in the next refresh drop in a few weeks. One of the things that will be nice about them is that they'll allow you to store your validation rules in your data model objects - and not have to write validation rules within the Controller or View itself. This makes validation very powerful - since you can change a rule in one place and have all of the UI and Controllers respect them. I'll blog more details about how this works once it is available.

    Hope this helps,

    Scott

  • Hi Clashfan,

    >>>>>>> Just found out about asp.net mvc today. Looks really cool. It seems like it's based alot on Rails, is this true?

    ASP.NET MVC uses concepts from a lot of existing web based mvc frameworks - including Tapestry, Rails, Django and more. It also obviously has a lot of goodness from existing ASP.NET, plus a few extra new innovations added as well.

    We hope it provides a nice mix and integration of a lot of good ideas, and contributes some of its own. :-)

    Thanks,

    Scott

  • Hi Erik,

    >>>>>>> So how does this relese play with SP1?

    This release will work with both .NET 3.5 as well as .NET 3.5 SP1 (and VS 2008 SP1).

    Hope this helps,

    Scott

  • Hi Padgett,

    >>>>>> One question: In preview 2 you couldn’t overload action methods, will this change?

    Good question - I need to check with the team to see if overloaded action methods are supported yet. I don't think they are yet though.

    Thanks,

    Scott

  • Hi Torkel,

    >>>>>>> Regarding ajax helpers, are there any plans for making the underlying javascript framework pluggable? So you can use JQuery or Prototype for example?

    Yes - that is something we are looking at hopefully enabling. You'll definitely be able to use JQuery or Prototype with ASP.NET MVC. What isn't clear yet is whether you can swap out our helper methods for alternative implementations. You will ceretainly be able to add your own to the existing ones though.

    Hope this helps,

    Scott

  • Hi BenB,

    >>>>>> Does it play well with the SP1 Beta?

    Yes - I'm using SP1 Beta on my machine and ASP.NET MVC Preview 3 works great with it.

    Thanks,

    Scott

  • Hi Shiju,

    >>>>>>> Has this version support VWD express 2008?

    Yes - ASP.NET MVC Preview 3 will work with VWD Express 2008 as long as you have SP1 Beta installed (since that is the version that added class library and web application project support - which MVC requires).

    Hope this helps,

    Scott

  • Hi Paul,

    If you have Team Suite or VSTS Tester Edition you could use Web Tests, record a test and add assertions to verify that either certain HTML Headers are included, that certain tags have a particular value for an attribute and stuff like that. Is a really powerful testing engine. Is not unit testing, but can be an alternative solution.

    I know you were talking about testing the view in isolation. It probably wont be that hard to hook dummy controllers with actions that simply set the ViewData you want to test your View with. The cool part is that you can also use the same kind of Web Tests to test the rendering, do end to end functional verification and load testing.

    The bad part is you need one of the mentioned VS Team System SKUs. A friendo of me told me about an open source product that does something similar, if you need it I can ask for the name. I know it's not integrated with VS, but finally it's for web testing.

    I have not gotten to deep into this MVC Framwork, but it might be possible to swap the implementation of the controllers and their actions at Design Time for one that only set hard coded ViewData, but at runtime it would use the real controller. Anyway you would still have to compile the dummy controller and recompile everytime you change it. Obviously there could be a better solution to this problem, probably setting ViewData in the actual view. I dunno. Silverlight uses some special tags for design purposes (that are only support in blend for now and not VS 08), something like that would be useful.

  • >>>>>> URL Routing is a little different than the URL Rewritter class (and is much, much richer). In the Url rewriter scenario you are taking one URL and transforming it into another that is ultimately executed. With URL routing you skip this transform step and instead route a URL directly to code to run.

    But the url routing module is now released separate from MVC, so it can be used with web forms right? But then you don't have controllers, you just have aspx pages. How is the url routing valuable for web forms?

    And another question: are there any improvements for rendering components (sort of partial views with their own controller)?

  • Hi Scott
    Your blog posts are always really great, but maybe you could put the date of the post at the top of the post? If I come to your blog from a link elsewhere, and you begin by saying "This morning we...", it's not clear whether or not it's current, and it would be nice not to have to scroll down to the first comment to find out how old the post is.
    Thanks for the great posts!

  • Hi Scott,
    It looks good so far, one of the things that I was toying with in the previous preview was asynchronously starting my business logic from the controller, then when completed in the call back call RenderView. &nbsp;I never got around to trying it so I don't know if it would work, but looking at the required "return ActionResult", the results of our model queries i.e. the business logic will have to be on the same thread as the call to the controller, thus no longer allowing us to asynchronously process our business logic. &nbsp;I won't be able to process the view rendering code asynchronously any more.
    Kind Regards,
    Paul

  • Scott,
    Thanks for all your responses. One more question. Currently if your Controller method Properties are populated from a form, you can not have the strongly typed action links for your form. Is there anyway to indicate to the URL builder that certain parameters should not be used when searching the out bound routing for a match (because they will be loaded from the form?) or conversely is there a way to Indicate in a route possibly in the defaults that certain parameters are populated by the Request.x?

  • Hi Scott,

    today I have to use the Html helpers. Is your team plannning support controls as in Web Forms?

    Regards,
    Ladislav

  • Just curious, but why are the routes configured in code, versus defining a new declarative section in the web.config?

  • Thanks you for your framework, but I have some problems with running assemblies on Linux with Mono. I have not enought money to by Windows&

  • Scott thanks so much for the work on this and the lucid description. I feel strongly that Mvc framework is easier to understand for new web developers than web forms. Here's wishing that you and your team keep up the hard work

  • Any talk about a CodePlex tool to port Monorail apps to MS MVC?

  • Thank You, easy to upgrade from the previous preview. I'm liking the idea of seperating this more and more from ASP.NET Extensions.
    It looks like this release has gone one step further by reseting the version to zero. The last preview or the ones before that seperated the logic out from the Extensions.dll and made libraries for each funcational part (Abstraction, MVC, Routing).

  • Hi Mike,

    >>>>>>>> But the url routing module is now released separate from MVC, so it can be used with web forms right? But then you don't have controllers, you just have aspx pages. How is the url routing valuable for web forms?

    ASP.NET dynamic data uses the URL routing system to get custom URLs for web-forms. The URL routing system actually allows you to register handlers independent of MVC.

    >>>>>>>> And another question: are there any improvements for rendering components (sort of partial views with their own controller)?

    You can render user controls today within views. We don't have ways to build sub-controllers - which are associated with user controls. That is something we are looking at enabling in the future.

    Thanks,

    Scott

  • Hi Paul,

    >>>>>>> It looks good so far, one of the things that I was toying with in the previous preview was asynchronously starting my business logic from the controller, then when completed in the call back call RenderView. I never got around to trying it so I don't know if it would work, but looking at the required "return ActionResult", the results of our model queries i.e. the business logic will have to be on the same thread as the call to the controller, thus no longer allowing us to asynchronously process our business logic. I won't be able to process the view rendering code asynchronously any more.

    With server applications you typically don't want to try and use async unless your work is going to be blocked (for example: waiting on a network or database response). If you are simply running code that does processing logic, it is best to not yield the thread - since ASP.NET will manage the worker threads efficiently for you by default.

    ASP.NET does support async execution today so that when you are blocked by network access, you can yield back the thread and ask ASP.NET to call you back once the network data arrives. We don't support this natively in MVC yet - although we've designed MVC so that we can support it. Logically you'd do something like:

    public ActionResult StartSomeWorkAction(int someparam)
    {
    // start network activity

    return new AsyncResult(HandleToNetworkEventNotify, new AsyncEventHandler(ContinueWorkWhenNetworkReturns));
    }

    public ActionResult ContinueWorkWhenNetworkReturns(object data)
    {
    // work with the data passed

    return View();
    }

    Hope this helps,

    Scott

  • Hi Erik,

    >>>>>>>> Thanks for all your responses. One more question. Currently if your Controller method Properties are populated from a form, you can not have the strongly typed action links for your form. Is there anyway to indicate to the URL builder that certain parameters should not be used when searching the out bound routing for a match (because they will be loaded from the form?) or conversely is there a way to Indicate in a route possibly in the defaults that certain parameters are populated by the Request.x?

    Good question - I'm not entirely sure if this is supported. Have you tried posting on the MVC forums at: http://forums.asp.net? That might be the best place to confirm.

    Thanks,

    Scott

  • Hi Ladislav,

    >>>>>>> today I have to use the Html helpers. Is your team plannning support controls as in Web Forms?

    That is something we are looking at enabling in the future as well.

    Hope this helps,

    Scott

  • Hi Curious,

    >>>>>>> Just curious, but why are the routes configured in code, versus defining a new declarative section in the web.config?

    You could declare this in a web.config or alternative configuration location as well if you want.

    Hope this helps,

    Scott

  • > Developers can use the new "Extension Method" mechanism to add their own custom helper methods to these objects.

    So here's something I just spent way too long to figure out - in order to get your extension methods picked up, you have to define them as part of the System.Web.Mvc namespace, not any downstream namespaces that you're using (web application/framework/etc.). The ASPX pages apparently only manage extension method namespace resolution that far in.

  • There is one thing thats dear to me and hope ASP.NET MVC will "NOT" take up the much filled and feature pack of its predecessors. ASP.NET has been very good but I noticed that the wants of everyone seems to put you and your team packing the framework with feature after feature. I hope ASP.NET MVC will be light, with great emphasis on performance and speed from the get go. I am very glad for your answers in relation to Rails. This gives a lot of people perspective as to where ASP.NET MVC is going in comparison to what they are using today (Rails, Django etc). I'm definitely looking forward to try ASP.NET MVC. I'm currently using Rails but will move to ASP.NET MVC in a heart beat if done right and it looks like your team is on the right path.

    PS: If you can elaborate on any performance metrics of ASP.NET MVC vrs ASP.NET some time in the future, that would be great.

  • Hi Dave,

    >>>>> Developers can use the new "Extension Method" mechanism to add their own custom helper methods to these objects....So here's something I just spent way too long to figure out - in order to get your extension methods picked up, you have to define them as part of the System.Web.Mvc namespace, not any downstream namespaces that you're using (web application/framework/etc.). The ASPX pages apparently only manage extension method namespace resolution that far in.

    Actually - you can put the extension methods in any namespace. The trick to having them show up, though, is to make sure that namespace is imported on the page (the reason putting it in System.Web.Mvc worked for you was because it was already being used by the page).

    You can cause your own custom namespace for extension methods and register them for the page in one of two ways:

    1) Add a declaration at the top of your .aspx/.master/.ascx file

    2) Edit your web.config file and register your namespaces within the section. This adjusts the default namespaces used by all files in your project. If you add your custom namespace there, your extension methods will automatically be usable everywhere. This is usually the approach i'd recommend.

    Hope this helps,

    Scott

  • Hey Scott,
    I've been wondering since you first implemented the attribute filters.. I wondered why you decided to let the attribute instance itself plug into the execution?

    What I mean is, what if I want an attribute that relies on being defined multiple times.. say:

    [MyAttr(something1)]
    [MyAttr(something2)]
    [MyAttr(something3)]
    ActionResult MyAction()
    {
    }

    I want to be able to evaluate my filters action based upon all those attributes..

    Would it not be cleaner if filters ultimately worked a bit like behaviors in WCF?

    So essentially you would have an instance that handles executing a specific action, and it would have a collection of filters.. when the action is starting, the filters get notified, and can subscribe to events that occur throughout the stages of the actions execution..

    You could easily create the current attribute functionality from this, but now we have this much more powerful filtering system..

    You could register filter types to methods or the controller itself, something like:

    [ActionFilter(typeof(MyActionFilter))]
    ActionResult MyAction()
    {
    }

    interface IActionFilter
    {
    void Initialize(ActionExecution context);
    }

    class MyActionFilter : IActionFilter
    {
    public void Initialize(ActionExecution context)
    {
    context.ActionStarting += .. event handler ..
    context.ActionComplete += .. event handler ..
    }
    }

  • Hey Scott,

    I agree with you on the HTML asserts, I was thinking more of the data content flow through, its probably more for regression bugs in view changes for non-happy path application flow... Just being able to test that controller code for a web site is a fantastic step forward!

    [Crazy ideas on]

    Just on my comment "Even better, in the designer having the same pricipal for the preview mode saving the whole cycle of building/running the site to check changes to the rendered view"... My dodgy hack (if I owned the code base for ASP.NET!!) to get that going was a "test view code behind file" that simply contains methods that populates the view data. On the designer you select one of these methods from a dropdown (or whatever) and hit "refresh". The ASP.NET engine renders the code, calling the dodgy test view code-behind and you get a wiz-bang no-fuss (very limited!) preview. I thought code behind because then you get intellisense etc.

    [Crazy ideas off]

    PK :)

  • I really love the MVC Framework, but without designer support, it's dead in the water. Hopefully this will be addressed down the road. I love bleeding edge. My clients do not.

  • Thank you scott, I think making a new project and just transfering all the models, views and controllers are a lot easier than the migration guide

  • foreach (var product in ViewData.Model)

    Model is object,not has GetEnumerator()

  • Hi czcz1024,

    >>>>>>>> foreach (var product in ViewData.Model) Model is object,not has GetEnumerator()

    If you ViewPage derives from ViewPage the ViewData.Model is of type "object". However, if you subclass ViewPage it will be typed as the type you define.

    So for example:

    public class MyPage : ViewPage<List>
    {

    }

    Will allow you to write (with full code intellisense):





    Hope this helps,

    Scott

  • I look at the ASP.NET MVC very carefuly, and I thing there are very good things.

    But I don't undestand why the HTML helpers approach is the prefered solution. On my point view, using Webforms for rendering could still a good solution. Richer solution, easy to extend, easy to reuse.

    Today, there is only few support (missing something like DataSource="ViewData.Model.Countries")

    Why this choice ? What are the plans for the future ?

    Cheers,
    Jeff

  • It's interesting. I try it now.
    Thanks ScottGu!

  • I've used ASP.NET MVC since January and think it's excellent. I have one question regarding the URL routing, though: have you considered basing the routing syntax on the upcoming IETF specification "URI Template" which seems to be the basis for a lot of other MVC frameworks being developed?

    It would be neat to have one URI templating syntax across all MVC frameworks.

  • Scott,

    First let me say that you have the best .Net blog! I get worried if I don't see your weekly links that you post. I am totally committed to LINQ after reading your examples.

    I've been reading that MVC in asp .Net will move web apps away from using state and there is supposed to be several other reasons that will make it appealing. I've been looking into Ruby on Rails and (I'm sure you know) it follows the mvc framework.

    My question is this: Is this the future of asp .Net? I'm very intrigued and have started reading up on this to start to see if it is viable to pursue learning it so I create my next project with it. Or is it possibly going to be looked as more of a hobby type app?

    Thanks for your time both on my question and your hard work on this blog!

    Wali

    p.s. I know you break your fingers with all the code you must right; but is there a way some of your examples could include VB code too. I promise I'll know c# by time I finish translating all the examples I see. :-) Thanks

  • It should be cool to be able to pass a dummy text (like "[Please select]") inside a DropDownList.
    So it should be something like that.

    new SelectList(MyItems, "Id", "Name", selectedValue, "[Please select an item]")

    It is a common case to find such DropDownLists and the current solution needs some transformations due to the strong typing of inserted items.

    What do you think about it?

  • Hi Scott!

    Currently I've been developing our core application using ASP.Net MVC and Linq, and development progress almost 99% finish.
    My question is, can I use this "MVC Preview 3" in our production server?

    When the "ASP.Net MVC" full release version will be Launched?

  • Hi Scott, great post and the updates to MVC are looking great too!

    I've been waiting for some routing updates. I'm hoping for support of routing based on the host name. I'd like to be able to pass it as a parameter to controller actions, and also to alter the routing rules based on the domain.

    For instance, I would like domain1.com/about to route to the About() action method on the the Home Controller, but domain2.com/about to route to the ShowPage() action method on the Wiki Controller.

    Eilon told me how I could do this by deriving from Route and overriding the ProcessContraint method (http://forums.asp.net/t/1249663.aspx), but it would be good to see it built in. Thanks again.

  • Don't mind if you keep this off the blog comments, ASP.NET is really taking your concentration of the big game so in that light here it is:

    Simplest SilverLight WishList

    Just to be able to build a full-blown size app before it takes 120MB for a simple couple of controls. It shouldn't really take more than 20MB if that. Get more complex it goes past 200MB which is a joke right.

    Also the ability to stream data, include an efficient SSL implementation and great Grid.

    If that is a lot to ask and this doesn't even work on faster WinForms, it won't work on WPF, heck on anything Windows but native code.

    So just a little bit of effort and that bloat might actually succeed one day and take Adobe out.

    Lowest footprint, for real big data, proper and ultra-fast text rendering (create a new mode for all I care), and streaming network stack with security that is fast.

    I don't see any other way out.

  • Hi Scott,

    Would it be possible to implement a "Please select" item (so an HTML option with an empty value) to the DropDownList?

    Currently, I must patch the rendered output to insert such an item at the first position.
    There are cases where this can be useful, for instance if you have a DropDownList which allows to select a null object inside the Model.

    Thank you for such a good release by the way.

  • Hello,

    why the type of Model propery of ViewData has to be reference type? Sorry I don't get it.

    Igor

  • Hi Scott,

    Can you please provide instructions on how to deploy an ASP.NET MVC to IIS? I happen to use IIS 6.0 on Windows Server 2003, but other people may be using some other type of environment. I plan on deploying my project to a customer very soon, even though this is still a "Preview". It works well enough for our needs.

    Also, I'd like to see examples on how to create a second controller so I can navigate the user to another part of the website, which may or may not use ASP.NET MVC. In my own website, I'm trying to figure out how to create a pop-up window that has a report viewer control invoked via a button click inside the ASP.NET MVC "/Home/Reports" page. Each button on that page brings up a different report, with default parameters passed in (startdate and enddate).

    Thanks a lot!

  • I've installed this new preview, but noticed that Data Scaffolds are no longer a template choice. Where they removed purposely, or was this an oversight, or did I do something wrong when I installed?

  • Good work, like it.
    JsonResult needs "JsonOutput" string property (or maybe just overridden "ToString" method).

  • Scott,
    In your example code where you are pulling the categories from your NorthwindDataContext, I noticed that you're not wrapping it with "using" (i.e. not explicitly disposing the data context), which consequently allows your code to work since the data context isn't disposed by the time your list of categories reaches the view.

    I'm curious as to why you are not explicitly disposing it. In my code, I explicitly dispose of the data context which means I would have to call ToList() or ToArray() on my IEnumerable so that the query is executed. Is the data context being taken care of (disposed) behind the scenes? Or is this snippet just simplified and doesn't include such code to keep it as simple as possible?

  • Hi Scott,

    One concern: the coding style in Browse.aspx looks like going back to classic ASP style with a lot of "", such as and , etc..

    I'm kind of confused. Are we supposed to go oppositie direction of "codeBehind" practice when using this Framework?

    Thanks.

    Mitchell

  • I'm curious on how the new MVC works on earlier version of IIS. On previous versions of IIS, in order to get .NET to run for a path that doesn't exist or doesn't end in .aspx, you had to add a *.* ISAPI filter. I haven't used it yet, but does IIS 7 do this automatically? And can MVC work on earlier versions of IIS without this?

  • What is the eta for the release of Asp.Net MVC? End of this year or sometime next year?

  • Hi Scott,

    I’m a little concerned with the direction you are taking by moving the model to a property of the ViewData rather than leaving it as the strongly type object. The issue I have is that you are promoting the use of untyped data.

    Up until now I’ve been using a transport class that each controller defines internally. This class derived from a base transport object that my base controller class populates with common information. In each controller fields and properties were added to suit the data being passed to the view. Then all controllers, views and user controls use the appropriate transport class as their generic parameter.

    Now I appreciate that this can still occur with ViewData.Model; however, you Html helpers are now being focused on the dictionary entries (specifically lists), rather that strongly typed collections of appropriate business objects.

    I think this push toward forcing the use of untyped information is not such a good thing.

  • Hi Scott,

    RenderUserControl now seems to have a problem. Before when using a generic as the ViewData, you could pass your whole ViewData to RenderUserControl. Now you can't. There seems to be now way to get both the Dictonary and the Model object to a usercontrol rendered this way.

    I'm using seperate userscontrols to render a common 'form' for the various model objects (keeping it DRY). Now that I can't pass the whole ViewData (and Model) to RenderUserControl I can't use the Html.DropDownList to render select boxes because the dictionary in the ViewData on the usercontol doesn't get populated.

    ScottEg

  • i'm getting this error, "The controller for path '/' could not be found or it does not implement the IController interface.
    Parameter name: controllerType
    "
    after updating to preview 3! HELP!

  • Hi Scott,

    Before this change I would sometimes call RenderView several times from a controller action to render different pieces of the page in response to an AJAX call. How can this be done now?

    ScottEg

  • Hi Stephen,

    >>>>>>> I've been wondering since you first implemented the attribute filters.. I wondered why you decided to let the attribute instance itself plug into the execution?

    Good questions on the attribute syntax - I sent off some mail to the team to ask them about this.

    Thanks,

    Scott

  • Hi Asbjorn,

    >>>>>> I've used ASP.NET MVC since January and think it's excellent. I have one question regarding the URL routing, though: have you considered basing the routing syntax on the upcoming IETF specification "URI Template" which seems to be the basis for a lot of other MVC frameworks being developed?

    I'm not that familiar with that proposal - although from a quick look at it, it looks like out URI templating approach is consistent (we use the same { } syntax). They have some interesting approaches for conditionally handling things which we might want to add in the future.

    Thanks,

    Scott

  • Hi Labilbe,

    >>>>>> It should be cool to be able to pass a dummy text (like "[Please select]") inside a DropDownList. So it should be something like that. new SelectList(MyItems, "Id", "Name", selectedValue, "[Please select an item]")

    That is definitely a scenario we need to support - I'll forward your suggestion along to the team.

    Thanks!

    Scott

  • Hi Tens,

    >>>>>>> Currently I've been developing our core application using ASP.Net MVC and Linq, and development progress almost 99% finish. My question is, can I use this "MVC Preview 3" in our production server? When the "ASP.Net MVC" full release version will be Launched?

    You can deploy your application on the current preview just fine (the license allows for it). We plan to ship the final "1.0" release of ASP.NET MVC later this year.

    Hope this helps,

    Scott

  • Hi Igor,

    >>>>>> why the type of Model propery of ViewData has to be reference type? Sorry I don't get it.

    The Model property can be a class that has any type of properties.

    Hope this helps,

    Scott

  • Hi Walt,

    >>>>>> I've installed this new preview, but noticed that Data Scaffolds are no longer a template choice. Where they removed purposely, or was this an oversight, or did I do something wrong when I installed?

    The ASP.NET Dynamic Data project template (which I think you are referring to) is now including in VS 2008 SP1. ASP.NET MVC will work with both VS 2008 and VS 2008 SP1: http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx

    Hope this helps,

    Scott

  • Hi Mohamed,

    >>>>> Good work, like it. JsonResult needs "JsonOutput" string property (or maybe just overridden "ToString" method).

    Here is a blog post I've done that talks about how to implement a ToJson() extension method on all objects: http://weblogs.asp.net/scottgu/archive/2007/10/01/tip-trick-building-a-tojson-extension-method-using-net-3-5.aspx

    Hope this helps,

    Scott

  • Hi Jayson,

    >>>>>>> In your example code where you are pulling the categories from your NorthwindDataContext, I noticed that you're not wrapping it with "using" (i.e. not explicitly disposing the data context), which consequently allows your code to work since the data context isn't disposed by the time your list of categories reaches the view.

    You could use either a using statement to handle this, or alternatively you can also override the Dispose() method on the Controller base class and dispose of it there. The Controller base class implements IDisposable by default - which means that the Dispose() method will get called for you at the end of each request.

    >>>>>>>> I'm curious as to why you are not explicitly disposing it. In my code, I explicitly dispose of the data context which means I would have to call ToList() or ToArray() on my IEnumerable so that the query is executed. Is the data context being taken care of (disposed) behind the scenes? Or is this snippet just simplified and doesn't include such code to keep it as simple as possible?

    The DataContext will get cleaned up by garbage collection eventually - although explictly disposing would be a recommended practice for any application that is going to be high volume. Note that the DataContext does not hold onto connections to a database, though, so you won't leak connections by not disposing it. However, the DataContext does maintain change tracking information (which consumes memory), which is why explictly disposing of it is probably best.

    Hope this helps,

    Scott

  • Hi Mitchell,

    >>>>>>> One concern: the coding style in Browse.aspx looks like going back to classic ASP style with a lot of "", such as and , etc.. I'm kind of confused. Are we supposed to go oppositie direction of "codeBehind" practice when using this Framework?

    In addition to using blocks, we also support using server controls that you manipulate from code-behind classes. For example, instead of a for-loop using you could use a or control whose DataSource property you set via code-behind.

    Having said that, one of the things we see some developers excited about with MVC is the opportunity to drop down and have total control over their HTML/JavaScript (and not have to use a server control abstraction). Some people find doing that a step-back, others find doing that progress. A lot depends on your needs, background and perspective. We'll support both approaches - so you can choose whichever feels most natural and best to you.

    Hope this helps,

    Scott

  • Hi Jeff,

    >>>>>>>> What is the eta for the release of Asp.Net MVC? End of this year or sometime next year?

    We are planning to ship the "1.0" release of ASP.NET MVC later this year. It has a go-live license that you can use now to deploy applications early if you prefer.

    Hope this helps,

    Scott

  • Hi Poppik,

    >>>>>>> i'm getting this error, "The controller for path '/' could not be found or it does not implement the IController interface. Parameter name: controllerType " after updating to preview 3! HELP!

    My guess is that you might need to update your routing rules in Global.asax to use the latest routing rules semantics. If you still have problems I'd recommend posting to the MVC forum on http://forums.asp.net.

    Thanks,

    Scott

  • Hi Michael,

    >>>>>> I'm curious on how the new MVC works on earlier version of IIS. On previous versions of IIS, in order to get .NET to run for a path that doesn't exist or doesn't end in .aspx, you had to add a *.* ISAPI filter. I haven't used it yet, but does IIS 7 do this automatically? And can MVC work on earlier versions of IIS without this?

    With IIS7 ASP.NET MVC gets automatic extension-less URLs without you needing to configure anything (this works out of the box).

    With IIS6 and IIS5 (on WinXP) you have two choices:

    1) Map your MVC URLs to have an extension in them. For example: use a routing rule like: {Controller}.mvc/{action}/{id} instead of the default {Controller}/{Action}/{id} rule.

    2) Use a URL rewriter and/or have ASP.NET process all incoming URLs. This blog post here should help with this (note: it was written for an earlier mvc preview, but i think still fully applies): http://biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/

    Hope this helps,

    Scott

  • Hi Don,

    >>>>>>>> Can you please provide instructions on how to deploy an ASP.NET MVC to IIS? I happen to use IIS 6.0 on Windows Server 2003, but other people may be using some other type of environment. I plan on deploying my project to a customer very soon, even though this is still a "Preview". It works well enough for our needs.

    I just posted a comment immediately above this one that helps describe how to handle the IIS6 scenario. Also make sure to check out this blog post here: http://biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/

    >>>>>>>> Also, I'd like to see examples on how to create a second controller so I can navigate the user to another part of the website, which may or may not use ASP.NET MVC. In my own website, I'm trying to figure out how to create a pop-up window that has a report viewer control invoked via a button click inside the ASP.NET MVC "/Home/Reports" page. Each button on that page brings up a different report, with default parameters passed in (startdate and enddate).

    I'm hoping to-do some more tutorials soon that show off how to handle some of these scenarios more. At a highlevel, you can either add a .aspx page to your site and link to it (if you are using the reportviewer server control). Or, if you want to build the second page using ASP.NET MVC just add a second controller class to the project and link to that.

    Hope this helps,

    Scott

  • Hi Scott,

    >>>>>>>> I’m a little concerned with the direction you are taking by moving the model to a property of the ViewData rather than leaving it as the strongly type object. The issue I have is that you are promoting the use of untyped data. Up until now I’ve been using a transport class that each controller defines internally. This class derived from a base transport object that my base controller class populates with common information. In each controller fields and properties were added to suit the data being passed to the view. Then all controllers, views and user controls use the appropriate transport class as their generic parameter. Now I appreciate that this can still occur with ViewData.Model; however, you Html helpers are now being focused on the dictionary entries (specifically lists), rather that strongly typed collections of appropriate business objects. I think this push toward forcing the use of untyped information is not such a good thing.

    The main reason we moved to support both a ViewData dictionary API and a strongly-typed ViewData.Model sub-property is because we found a lot of scenarios where developers wanted to pass a strongly typed object to a View (for example: a Product model object), as well as pass a number of more transient properties (like Title, Message, etc). While people could build separate ViewModel classes for each custom view that encapsulated all of these properties, that ended up being a lot of work for most scenarios, and having a hybrid model like the one we introduced ended up being a lot simpler. Note that if you want everything to be 100% strongly typed you can - you just pass it as the Model object.

    Note that the HTML view-helpers we have work with both the dictionary API as well as the strongly-typed one. So when you write:

    it will check both for both a ViewData["ProductName"] item, as well as a ViewData.Model.ProductName property.

    This means that all the helpers will work with a 100% strongly-typed model if you prefer that (which I think addresses your concern).

    Hope this helps,

    Scott

  • Hi Scott,

    >>>>>> RenderUserControl now seems to have a problem. Before when using a generic as the ViewData, you could pass your whole ViewData to RenderUserControl. Now you can't. There seems to be now way to get both the Dictonary and the Model object to a usercontrol rendered this way.

    Can you post more details about this issue on the ASP.NET MVC forum on http://forums.asp.net? That way we can make sure to have someone from the team investigate.

    Thanks!

    Scott

  • Hi Scott,

    >>>>>>>> Before this change I would sometimes call RenderView several times from a controller action to render different pieces of the page in response to an AJAX call. How can this be done now?

    There are a couple of approaches you could take to accomplish this with the new bits. I'm assuming you were doing something like this with Preview 2:

    public void MyActionMethod()
    {
    RenderView("View1", myData1);
    RenderView("View2", myData2);
    RenderView("View3", myData3);
    }

    The simplest way to port this to Preview 3 would be to rewrite it like so:

    public void MyActionMethod()
    {
    View("View1", myData1).ExecuteResult(ControllerContext);
    View("View2", myData2).ExecuteResult(ControllerContext);;
    View("View3", myData3).ExecuteResult(ControllerContext);;
    }

    This works, although is a little ugly.

    A better approach would be to build your own custom ViewResult class that handles you multi-part AJAX update scenario. This would allow you to write something like below:

    public object MyActionMethod()
    {
    return new MultiAjaxResult {
    View("View1", myData1),
    View("View2", myData2),
    view("View3", myData3) };
    }

    To do the above you could derive MultiAjaxResult from the ViewResult base class and override the ExecuteResult method. Then add properties to MutliAjaxResult that you use to track the list of updates you want to have happen, and within ExecuteResult use those to generate the response.

    Note that one benefit you'll get from doing this is that it makes your code much easier to unit test - since you can now verify the behavior of your Controller without having to actually execute or render the views.

    Hope this helps,

    Scott

  • Hi Scott,

    I'll give the MultiAjaxResult class a go in a few days.
    I'll get onto the forum about the RenderUserControl issue tomorrow.
    I don't agree with the Viewdata direction :)

    How cool would a ViewData definition be if the languages supported this construct:

    public class ViewData: T
    {
    //dictionary stuff goes here.
    }

    This way the ViewData could derive from the model object.



    One option to make the syntax of the ViewData really clean

  • Great work so far. Looking forward to using it.

  • Hi Scott,

    Can you or someone from the MVC team comment on the changes to the Controller base class in Preview 3?

    I'm specifically interested in the disappearance of the virtual methods InvokeAction and InvokeActionMethod. I'm working with a project that depends on InvokeActionMethod and I'm not sure how it should be altered for compatibility with Preview 3.

    Thanks!

    - Adam Cooper

  • Hello, Scott.
    Trouble you again.
    I'd want to know how to design an action which need both render a view and redirect to another action.
    For example.
    I have an action named Login.
    First I check whether the current user is authenticated. If true redirect the protected personal page, or render the login form.
    I have been confused for this.
    Thank you.

  • Hi Adam,

    >>>>>>>>> Can you or someone from the MVC team comment on the changes to the Controller base class in Preview 3? I'm specifically interested in the disappearance of the virtual methods InvokeAction and InvokeActionMethod. I'm working with a project that depends on InvokeActionMethod and I'm not sure how it should be altered for compatibility with Preview 3.

    All those methods moved to the ControllerActionInvoker, which is much more customizable than the Controller was. Derive from that class and customize anything you need. Then on the Controller set its ActionInvoker property to be your custom invoker. You could set your custom invoker in the constructor of your controller.

    Hope this helps,

    Scott

  • Hi shinyzhu,

    >>>>>> I'd want to know how to design an action which need both render a view and redirect to another action.

    You could write something like this:

    public object Login()
    {
    if (Request.IsAuthenticated == true)
    {
    return Redirect("somepage");
    }

    return View("Login");
    }

    This will return a redirect if the user is logged in, or render a login view if they aren't yet.

    Hope this helps,

    Scott

  • Hi Scott,

    When can we expect a more final release? The MVC rocks!

    Thanks

  • Hi Scott

    Can you tell us as to when will the source code for the System.Web.Routing module will be available

  • In my project I'm dynamically adding ascx user controls to my pages. In earlier versions I just passed down the ViewData to the user control - now in preview 3 I've had to change the code to just pass the Model element. This is no problem, but I see why you changed ViewData to have these dictionaries (to let the controller do the work and keep the views simple) and I would like my user controls to use the full ViewData. Am I missing some insight that will let me easily pass ViewData down?
    Also, I'm working with Entity Framework in this project, and I've found that any MVC page throws an error if EF objects are used inline (i.e. on the aspx rather than the cs file). This happens no-matter what references I add, so I'm doing everything in the cs for now. Is this a known problem with EF and/or MVC?

  • Hello Scott.
    When will you post your long nice tutorial about ASP.NET MV preview 3?

    Thank you.

  • Hi,

    I understand that generic property "Model" can be any class. What I do not understand whay it has to be a reference type? For example we have a ascx control and this controls model is a value type. So whay Model has to be reference type?

    Thank you,

    Igor

  • I've just starting playing with the 3rd CTP of the MVC Framework and think it's great. While I hadn't yet toyed with the earlier releases, I've seen a lot of comments about those earlier releases to the affect of MVC being a complete alternative to traditional WebForms. However, from what I've seen so far they could actually work very nicely together.
    In a custom ViewPage, for example, I just added a form tag with runat="server". I was even able to take objects out of the ViewData collection and bind them to repeaters in the Page_Load event handler. Inside the repeater, I created data-binding expressions using Html.ActionLink(...) facility.
    My first impression is that having a hybrid between MVC and WebForms could actually be very useful. At a minimum, the ability to continue to use WebForms within MVC provides a bridge to a large volume of available third party controls and other assets that already exist.
    All that said, I haven't gone through and verified that WebForms in the context of MVC will work 100% the way I would expect. I haven't verified that ASP.NET Ajax and the AjaxControlToolkit work with MVC, but I'm crossing my fingers.
    Before going further down the path with MVC, I'd like to get a sense for whether what I'm doing by mixing MVC and WebForms is kosher and likely to be supported in future MVC releases.

  • When iterating over ViewData.Model in Browse.aspx how are you avoiding casting the object to IEnumerable?

  • Hi Scott,

    I downloaded the latest MVC preview 3 release and I am trying to use the MapRoute() and IgnoreRoute() methods and they do not seem to be available in the download. Is this included in this release, or is this a feature that will be added in the future? From your posting, I get the feeling that this should be available. The version of the System.Web.Routing.dll that I am referencing is 0.0.0.0, created on May 27th at 7:56:08 AM. Is there a different/newer versions available?

    Thanks!

  • Can I use ASP .NET MVC with Trust Level set to Medium in Web or Machine Config?!

  • Scott -

    Any update on the forthcoming blog post you mentioned at end of this post?

    -Ryan

    >> I also have a (very) long tutorial post that I started putting together this past weekend that walks-through building an application using ASP.NET MVC Preview 3 that I'm hoping to wrap up and post in the next few days.<<

  • Hi Scott,

    I was wondering how you make a https request from a http page via MVC using AJAX ? Is it possible and if so would you be able to post some code ?

    Thanks,

    Andy

  • I posted this comment before and it didn't appear so I am re-posting.

    In Browse.aspx you iterate over ViewData.Model. How do you avoid a cast to IEnumerable because ViewData.Model is of type object?

  • Did the source for this come out? I'm using express and the larger asp.net website storefront won't work with express. Thanks.

  • Did the source for this come out? I'm using express and the larger asp.net website storefront won't work with express. Thanks. Please delete this comment

  • Hi, Scott!
    When can we expect that tutorial post you mentioned earlier?

  • good review, thx

  • Scott,
    Will ASP.NET MVC be able to be broken out into separate projects with different .dlls? Meaning, all of the examples I have seen so far are for the Model, View and Controllers to reside in the same project. Will it be possible to separate these up into different projects? And if so, where can I find examples of this?

    Thanks

  • Hey Scott,

    MVC is awesome. I'm stuck on something. In my controller, I am passing back a MyDataView to the view. MyDataView contains my Person object and a few KeyValueItem lists.

    However, in order to get my data to appear in my view, i have to do the following:



    First Name




    This is fine for displaying the data, but when my update button is clicked and I use the following:
    BindingHelperExtensions.UpdateFrom(person, Request.Form);

    The problem is Request.Form is coming back empty with none of my Person attributes, thus not updating my Person object. Is there something additional that needs to be done to populate the Request.Form?

    Thanks!


  • Scott,

    I'm trying to create a dropdown list that is driven by a DataTable. In past releases of the MVC preview I have used the HTML.Select() helper function to accomplish this, but Preview 3 doesn’t seem to have the HTML.Select() helper anymore. I’ve tried using my DataTable.AsEnumerable() to create a SelectList in my controller and pass that to HTML.DropdownList in my view, but the SelectList() does not seem to support the DataTable Enumerable. I don’t get any errors, but it creates an empty dropdown list.

    Am I doing something wrong here, or is this just not supported in this release?

    Thanks,
    Bob

  • As I mentioned in a previous post in the MVC Preview 3 I could not get the SelectList / HTML.DropdownList() to work off of a DataTable (IOW, creating a dropdown list whose items are defined by the rows of a DataTable). Since I needed to get this working for demo, I created the following subclass of SelectList which hacks around the problem.

    public class DataTableSelectList : SelectList {
    public DataTableSelectList( DataTable dt, string dataValueField, string dataTextField )
    : base( dt.AsEnumerable(), ToExpression(dt, dataValueField), ToExpression(dt,dataTextField) ) {}
    private static string ToExpression( DataTable dt, string columnName ) {
    return string.Format("ItemArray[{0}]", dt.Columns[columnName].Ordinal );
    }
    }

  • How do you do dependeant dropdowns?

Comments have been disabled for this content.