General question as I start implementing ASP.NET MVC, I found myself asking, to avoid boxing and unboxing through the framework (check out the signature for “View”), why wouldn’t they have simply used generic methods for actions? Maybe they “should have” and they didn’t but maybe someone knows of a good reason.
Thanks in advance!
Sorry, an example would be like so…
Edit(int id)
{
...
if(...)
View<Contact>("Edit");
else
View<ShoppingCart>("Cart");
}
EDIT
UPDATED example to reflect my question more accurately
So I can do this:
Update:
Your updated code would just be syntactic sugar. The Model will still get box’d and unboxed when the MVC pipeline starts executing the action and rendering the view.
Even so if you wrote something like this, I’m assuming you’d actually want to pass a model along someplace. Your example doesn’t include it.
The generic parameter wouldn’t even matter so you’d end up with the same looking calls: