Thank you everyone who came to my one day ASP.NET MVC workshop at ASP.NET Connections. We managed to build an entire Movie Database application with unit tests and a reasonably good design -- Congratulations!

I've attached the Movie Database application and the demo code from the workshop below.

Workshop Code

If you liked this blog post then please Subscribe to this blog.
posted on Thursday, March 26, 2009 5:15 PM | Filed Under [ ASP.NET ASP.NET MVC Talks TDD ]

Comments

Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Jacob
on 3/26/2009 7:52 PM

So, this just follows the same principles as the contact manager you posted on asp.net/mvc.

I appreciate your work, however, I would like to request you use a different testing framework. MSTest is only available for VS Pro and Team. Something like nUnit would be nicer for us 2008 express edition users.

Thanks.
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Stephen.Walther
on 3/26/2009 9:09 PM

@Jacob - Yes, it has the same architecture as the Contact Manager application -- when I find something that works, I stick with it :)

Good point about NUnit for Visual Web Developers. Thanks.
Gravatar
# re: ASP.NET MVC Workshop Code
on 3/27/2009 3:37 AM

hi Stephen,

For 2 to 3 month, i am reading regarding ASP.net MVC Framework and also integrated it in my some intranet applications, it is awesome, it is solving alots of issues that i have faced in WebForm but i am also a big fain of WCSF, mainly it's plug able architecture.

We are designing a VOIP Exchange System that will work on Internet. For its web development, i had plan for WCSF but after designing some interanet application on ASP.NET MVC framework, i am thinking to desing my VOIP application using MVC but i need that plugable architecture.
I were thinking to replace the MVP with MVC in WCSF but my team don't have that much time.

please advise me what should i do?
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Francis Robert
on 3/27/2009 5:26 AM

I really like ASP.Net MVC for more than one reasons but there's just one thing that keeps me from using it, I just cannot figure out how to do the following...

All the tutorials I've found so far are based on a one-to-one model: list products, display one product, edit, create, delete... Same for your movie app.

What I would like to do is to display a blog entry in a view, followed by the comments associated to it (different model), and then followed by a form to post a new comment, while using the same default validation codes (Html.ValidationMessage...) which are created automatically.

I just can't figure out how to achieve this as it always complains about the model not fitting the view (excuse my french...). So a tutorial replicating this example or some guidelines would be very much appreciated! :)

Thanks for all your hard work!
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Eric
on 3/27/2009 7:04 AM

@Francis: I've done that by creating a class that aggregates model objects and using that as the Model for the view. So if you needed to pass both a PostCollection and a CommentsCollection (or whatever), those would be properties on this third class...whatever you call it. Has worked great for me.
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Stephen.Walther
on 3/27/2009 7:17 AM

@Francis, @Eric -- Yes, you want to create a view model class that exposes both properties. Then, use the following Inherits attribute at the top of your view:

Inherits="System.Web.Mvc.ViewPage"

There is a sample of this in the workshop code if you take a look at the Views\Movie\Index.aspx view.

Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Francis Robert
on 3/27/2009 9:16 AM

Thanks a lot!! I'll go study that. Nice! :)
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Mokhtar Aiad
on 3/27/2009 10:57 AM

I have viewed some examples but all of them have prerequities : using specific technologies(LinkToSQL .. and so on). Can you give ASP.NET MVC examples using well known and simple things like classic ADO databases manipulation. This will help many peoples.
For example: How to construct an ASP.NET MVC application with this 3 things:

1.A pure HTML/Javascript Form page with HTML input text tags for each field (say Customer.html of Notrhwind.mdb)
The page have 2 buttons: NextRecord and PreviousRecord having at Onclick_Event:getRecord(NextOrPrevious)

2.A javascript manual ajax GetRecord function, something like this:
function getrecord(NextOrPrevious) {
var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
var sURL = "getrecord.aspx?ID=" + NextOrPrevious;
oXMLHTTP.open( "POST", sURL, false );
oXMLHTTP.send();

var sResult=oXMLHTTP.responseText
var aRecord = sResult.split(";");

document.getElementById('CustomerID').value = aRecord[0];
document.getElementById('CompanyName').value = aRecord[1];
document.getElementById('ContactName').value = aRecord[2];
document.getElementById('Adress').value = aRecord[3];
... and so on ...

}

3. What is the SHORTEST and the simpliest way to program getrecord.aspx ? or VB/C# getrecord controler function ? using something like ADODB Recordset. VB/C# GetRecord function will return a simple string containing the current record fields values separated by comma. (but without using other things like LinkToSQL, views, models , Json, XMl, or other entities.)

Think you very much !
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by josh
on 3/27/2009 11:20 AM

Thanks a lot!
Gravatar
# RE: ASP.NET MVC Workshop
Posted by EricB
on 3/27/2009 12:35 PM

Your sessions were great Stephen. I really enjoyed them. I stayed the extra day for the MVC workshop and was glad that I did. I am NOT sold on the Entity Framework and I am disappointed with the inherent support for JavaScript in MVC but this framework seems to be right up my alley. Thanks again.
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Timur
on 3/27/2009 11:27 PM

Are there any places where I can watch it? like MIX09 or PDC? Or this is just a "private" conference, in the sense that it's not been published on the net?
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Mokhtar Aiad
on 3/28/2009 5:17 AM

Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Alex
on 3/29/2009 10:07 PM

Hi Stephen,

Is it possible at your side to send me a step-by step guide on the Movie App so that I can practice at my free time? Thank you.
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Jack
on 3/29/2009 11:26 PM

The code is of high quality, We can learn a lot from it!
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Stephen.Walther
on 3/30/2009 7:56 AM

@Alex -- There is both a written and video version of the Movie Application tutorial at http://www.ASP.net/mvc
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by EricB
on 3/30/2009 8:11 AM

I have a question about the design gallery. Why is that the master page references a code behind file? And where is it? It seems the layout blows in the face of MVC a bit or am I looking at it incorrectly. thank you. -E
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Stephen.Walther
on 3/30/2009 8:20 AM

@Eric -- Several of the designs in the Design Gallery are currently outdated because they were created while ASP.NET MVC was in BETA. We are planning on updating all of the designs to work with the final release of ASP.NET MVC within the next two weeks.
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by designx9
on 3/31/2009 4:35 AM

Please let me know whether i could find the code in vb.net too.

Thanks
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Eb
on 4/14/2009 6:04 PM

What is the purpose of the Service Class - why are you adding an extra layer. Also, how would one change datastore? Say I am using MSSQL now and in the future decide to use XML instead, how and where would I do this? It was v easy in the Provider Model. Sorry but new to this Repository Pattern stuff.
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Stephen.Walther
on 4/14/2009 6:08 PM

@Eb - According to the Single Reponsibility Principle (SRP) a class should have a single reason to change. You don't want to mix validation logic with your controller logic and data access logic. In the sample application, the controller logic is in the controllers, the validation logic is in the service, and the data access logic is in the repository.

Because classes that interact with the repository interact only with the IRepository interface, you can easily swap a new repository for the existing one. Just implement the IRepository interface with the new class.

Hope this helps!

Stephen
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Eb
on 4/14/2009 6:37 PM

Thanks for your instant reply (you are good!!). OK get you bit about validation logic. I am still confused about plugging in various datastore. Only way I can think of changing repository is probably by loading Repository type via some configuration section in the Web.Config (like loading default provider in the Provider Model). Also, I think the type can be loaded via Global.asax.

Please clarify - thanks
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Stephen.Walther
on 4/14/2009 6:42 PM

@Eb -- Yes, that's right. If you don't want to hard code the repository then you can (a) Use something like the provider model (b) Set the repository in the Global.asax (c) Use a Dependency Injection Framework like the Microsoft Managed Extensibility Framework(MEF).
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Alex L
on 5/2/2009 8:23 AM

Stephen,

Nice and simple video/tutorial.

I followed the instructions to remove the id field from the Edit view by removing the following code:



<%= Html.TextBox("CampaignId", Model.CampaignId) %>
<%= Html.ValidationMessage("CampaignId", "*") %>



and now I am receiving a NullReferenceException on the Model object in the next field of the Edit view:



<%= Html.TextBox("CampaignName", Model.CampaignName) %>
<%= Html.ValidationMessage("CampaignName", "*") %>



What is causing the Model object to be null if the id is not present?

Thanks!
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Alex L
on 5/2/2009 8:32 AM

The HTML code was removed in the above. This is the line of code in the view where the Model object is null:

Html.TextBox("CampaignName", Model.CampaignName)

Is removing the id field from the Edit view causing the Entity Framework not to populate the Model?
Gravatar
# re: ASP.NET MVC Workshop Code
Posted by Karl Kopp
on 5/13/2009 5:53 PM

Thanks - loving MVC but not a lot of code around at the moment, so this is great...
Comments have been closed on this topic.