Hi Richard,
rjcox:Another example of an action that needs to select different views would be a "New" or "Update" action that processes a data collection form.
I see what you mean, but in this particular case
New and
Update are different actions and they can render different views and return different values as well as the same one.
And they should really render a view and not return a value.
Saying "action is returning a value" I meant the result of an action is a serialized Object (in some format) that is returned to a client. It has a little with the View itself.
Anyway, as we all already pointed, it is really so simple to "Jsonise" or "Xmlise" an object in the controller's code, so a return value just becomes non-practical.
Still, it should be useful some way :) Why should we lose this simple and basic feature of language :)
What I thought - is just a similar approach to .ASMX service methods.
There's another thought about return values. Most of actions end with RenderView call, even the view is chosen dynamically.
In most cases there is no code after the RenderView is called. This is exactly returning a value.
So why not return a ViewDetails as a return value?
Imaginary code:
public ViewData Find(string name)
{
if (string.IsNullOrEmpty(name))
return new InvalidArgumentView("name", name);
var result = GetTheObjectsFromSomewhere(name);
if (result.Count > 0)
return new ViewData(result);
else
return new NoResultsView(name);
}
This will also (probably) allow much easier Views testing.
I don't know why, but I feel like we can benefit from return values :)
Cheers.