Reputation: 47597
I'm curious why it's made exactly like that?
If i call this through AJAX:
public ActionResult Foo(){
return RedirectToAction("SomethingThatReturnsPartialView","Bar");
}
It won't return me partial view in AJAX callback but will redirect to url that represents action.
So - why it is so? What are possible workarounds?
Upvotes: 1
Views: 2935
Reputation:
Because when the browser receives the reply from the server that is a HTTP 30x redirect, it will do just that, regardless of how the request was initiated, either synchronously or asynchronously.
On of the possible workarounds could be something like RenderViewToString, but as we know MVC lacks this feature yet. It's a known missing feature everyone wants to get.
Look in this discussion: Render a view as a string
And also look here, there may be an option to prevent the browser going redirect with JavaScript: Catching 302 FOUND in JavaScript
Upvotes: 2