Atlanta ASP.Net MVC Developer/ Architect
ASP.Net MVC
jQuery DivFlip of MVC Partial
Nov 9th
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?
Jun 17th
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:
- Read the book ASP.Net MVC in Action (Work in Progress via MEAP)
- Attended Microsoft’s Firestarter in NYC
- Read a raft of blog posts
- Used the Northwind and other code samples
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.