Category Archives: ASP.Net MVC

Jan 2009 ASP.Net MVC Slides

Update: The Release Candidate has been released. The demo below works fine with it too.

>> Click here to download the slides and second demo. <<

Wow! We had a fantastic turn-out last night, interest in MVC must high!  Not having presented for almost a year  I tried not to publicize the the talk; but still instead of the expected twenty to thirty people there must have been close to a hundred and we had to expand the room! Couple this with the Microsoft building now almost impossible to find with that road closure flummoxing us coming from the south-side – who knows how many found Old Roswell gone and went back home at that point. For those that missed last night this talk will be repeated at all local code camps that happen in the next few months, the Atlanta one is in March and 2009 details will soon appear at http://www.atlantacodecamp.com/.

Obviously that presentation covered only some of the very basics and there is a lot more to working with MVC. Watch this space for more MVC tips and if people request it, I’ll put together a deeper presentation for Code Camps etc.

Also, I was not kidding about the free presentation/ training at your company. Totally free, no creepy sales people will call afterwards either – it will keep my hand in while taking a few months out from real work and with luck one of them might lead to my next gig (which will use MVC).  So if you have at three or more devs drop me a line via the ‘Email Me’ page on this blog – don’t worry if you are a small or large shop, I just want to spread the word and try to ensure there are a selection of MVC Contracts out there when I get bored of goofing off :)

IIS7 Gotcha – COM Error 80040154

We have all seen the 80040154 COM error. Normally the solution is to run regsvr32 on the com dll so it is registered on the machine.

“System.Runtime.InteropServices.COMException (0×80040154): Retrieving the COM class factory for component with CLSID {D1CB0D81-7D2B-4064-9AC7-D0D88DEC3D16} failed due to the following error: 80040154.”

Of course regsvr32 was the first thing I did, but the error still happened in the ASP.Net MVC project on IIS7/ Server 2008. Using regedit.exe verified the dll was registered, so I ran the NUnit tests… same error! The solution is to permit the IIS7 App Pool to run 32 bit code as shown below:

IIS7 COM Gotcha

IIS7 COM Gotcha

jQuery DivFlip of MVC Partial

So you have a Partial in a div and would like to flip out the html contents with new results from just the partial… To para-phrase Obi-Wan ‘this is the JavaScript you are looking for’:

function Save() {
  var data = $(‘#PartialData’).serialize();
$.post(
‘SavePartial’, data, function(result) {
    if (result == “success”) {
    $(
“#DivFlipThis”).load(“ProductUserControl”);
}
    else {
alert(result);
}
});
}

It uses jQuery to serialize form data, then an Ajax post sends the data to a controller action which auto-binds it to the model. All in all there are very few lines of code. If anyone needs to see the controller actions they can be found in this tiny sample project DivFlipExample.zip (click to download). It runs stand-alone and needs no database so is MVC noob safe :)

For the projects that pay my salary (high traffic public facing websites) we have a more sophisticated technique using JSON to read a .Net class graph of errors, success message etc passed from actions to the JavaScript. The JavaScript then does a divflip, redirect to next action, shows success or error messages as applicable. It is very simple too.

So, to the MVC experts out there: Am I missing something? RoR does this kind of thing auto-magically (so our RoR team says). For hours I searched Google on how to refresh an MVC partial without doing a whole page refresh. There were many people asking the same question and lots of people like my friend Rusty Zarse becoming very frustrated, but no-one had an answer that helped us. All the demos I used to learn MVC (MVCNorthwind, MVC Commerce, MvcMembership, Suteki, MVC Storefront) need full post-backs for anything semi-significant.

MVC guru == PhD wannabe?

This is a plea to anyone who blogs, writes or talks about ASP.Net MVC. This stuff is pretty simple, let’s not scare people away.

In the last four weeks of learning MVC I have:

All are guilty of requiring niche knowledge in some or all of:

  • Domain Drive Design
  • The Repository Pattern
  • JSON, REST etc
  • Automated Developer Testing
  • Mocking Frameworks
  • Active Record, NHibernate, LINQ to SQL – insert any other non mainstream data access technique here
  • Differences between MVC, MVP, Front Controller etc
  • Lamda expressions

Apparently every educator is trying to showcase their knowledge in a manner that is inaccessible to 95% of developers.  The presenters I saw at NYC are great guys, but almost all the faces in the audience soon were blank as decks became PhD thesis material. We soon dwindled down to ~50% attendance. I chatted with several ‘regular guys’ over lunch and they were pretty annoyed – what they need to see are simple samples.

Missing Samples: Hopefully the Manning book will improve before publication – the first chapter got me going with the framework, but the rest was almost useless to me. People who care about DDD, MVC details etc already know about them. What we need to see is samples of Grid controls, binding data to controls, how we get data back from a postback etc. At work we soon had screens working with jQuery and ext; perhaps because we do not worry about DDD, strict patterns etc?

Of course there is the argument that MVC is not targeted to all developers and only super-intelligent ones will understand MVC. Poppycock, RoR has been a huge success due to its simplicity – how many RoR developers know they are using Active Record? Not many I would gamble; most RoR people just want to build something quick and don’t have a CS background. MVC is not that hard, let’s present it clearly and simply guys.
Oh yes, and I do think the ASP.Net Framework is heading in the right direction. There again I love NUnit and wrote my own MVC framework for WebForms back in 2003 as I did not know how else to test my ASP.Net screens.