Is it possible to build a hybrid ViewResult that returns in depedency of an AjaxRequest or HttpRequest a PartialViewResult
or ViewResult
?
IsAjaxRequest --> return PartialViewResult !IsAjaxRequest --> return ViewResult
As far as I know my HybridViewResult should derive from ViewResultBase.
But how to implement the FindView method?
This is a slightly more stripped down take on eglasius's answer. I'm actually tackling a similar problem except I need to return a JsonResult.
The (untested) NormalOrAjaxResult simply lets you specify an action result for the non ajax request and one for the ajax request. Because these are ActionResults you can mix up Redirect, View, Partial and Json view results.
Try:
Add any constructor & GetInnerViewResult variations as needed i.e. to pass Model.
can you not just make 2 different actions in that case? the 'shared' logic you could simply put in a
[nonAction]
method?I know I'm really late to the party here, but these didnt seem quite right to me, so here's my 2 cents:
With usage:
And then in your controller if you override View
Any action method where you return a view will automatically also return partials when requested: