Thanks for the post. I had a couple of thoughts about the implementation.
Composition over Inheritance is a best practice. By using inheritance you force all controllers to follow this behavior which will present the following challenges.
1) You're populating data for a master page that may not be used by every controller.
2) This may not be the behavior you want for your Categories controller. In the above scenario, I'd think you'd want to capture the data after the categories have been updated. You could just query the database again, but that is an extra db call.
An action filter seems more appropriate. You can be explicit in determining which controllers/actions implement the feature, and you can change the data fetched to match the master page being used and you'd still have the option of extending from a base class that used the attribute.
True, that is a possibility aswell.
However, some comments:
1 - I am not forced to use it in every controller, I can keep controllers specific inheriting from the usual class anyway. However, this approach does raise an issue with the coupling of controllers to views. Views are the ones who make use of the master.page not controllers, and while that is not a problem by itself, it's not the best option in terms of application structure.
2 - True, I am making an extra db call in every action method, but that can be easily sorted by implementing a caching mechanism, which is one of the goodies we get by building MVC over the ASP.NET framework.
How about implementing a dashboard/web part framework in MVC?
Another useful Quick Tip would be on implementing a skinning framework consistent with MVC
As an extension to the passing data to master pages, the use of server controls, such as building a menu control.
Thanks for the suggestions. I'll give it some thought as some of the suggestions are a bit outside-the-box from ASP.NET MVC, but if I can find a creative and simple solution to this, I will sure make a Quick Tip out of it
For the "WebForms VS MVC" debates: http://weblogs.asp.net/scottgu/archive/2010/01/24/about-technical-debates-both-in-general-and-regarding-asp-net-web-forms-and-asp-net-mvc-in-particular.aspx
Very true. ASP.NET MVC is simply an alternative to Web Forms, none is better than the other for every situation. It's mostly a matter of what suits you best, or which experience do you find more rewarding.
Phill Haack mentions in one of his sessions about ASP.NET MVC that the comparison between Web Forms and MVC can be looked at the same way you would look at manual vs automatic transmission in a car. They both allow you to drive a car, and none is better than the other in every possible scenario.
Thanks for the link!
Hi There, Im tryong to learn MVC and we hvae an existing application I want to re-do iusing MVC, I've added LINQ to SQL Classes including the stored proc i want to call - juist unsure as to how to go about it.
Can you show me an example or 2, perhaps calles with return values as well as insert sprocs wold be great.
Thanks
Gregor
Link to the template was broken, fixed it now
This is a great topic. I'm currently facing the very problem you're planning to address in your next post. The only method I've found is to pass the data for all the web parts to the view, then it's up to each web part to get the data it needs.
The only alternative I can think of is to use ajax calls from the web parts to populate them after the client has received the page. I think this method may be too resource heavy though.
It would be awesome if there is a better solution than either of these methods! Perhaps there's a way to accomplish it using some of those new MVC 2 features? Maybe areas?
I'll finish the post today and yes, that's the two alternatives I am covering.
I don't think you can use Areas for this...Areas are more like a project organization feature, since you can divide an MVC project in several areas, each with its own routes, controllers and views (at least that is my understanding of it). I honestly don't see how that can help us in the current situation.
I've just been planning something similar for my application. In terms of passing data to each web part I've found it beneficial to use RenderAction (part of the futures library on MVC 1.0). So far I've not noticed any great performance hit, although with dozens of webparts you may start to see performance degrade,
Thanks mate, a very good insight, do appriciate.