How to return a MVC View to a $.Ajax JSON POST

2019-07-05 05:33发布

问题:

I am sending a $.Ajax POST to a MVC Controller function with parameters and returning a JasonResult successfully. What I need to happen is that the current View be returned (as if it was not a JSON request and I was returning the Viewdata). The Viewdata has been updated and the page needs to be redrawn.

In short, I want the MVC Action to respond back to the $Ajax request correctly, and then have the page redrawn using the updated Viewdata. Hope this makes sense, coming down with a bad cold.

回答1:

Jason result, awesome.

It doesn't work like that i'm afriad, either you need to not use ajax, or you need to return data and handle it in jquery, or you need to return a partial view.

Partial view is probably the best solution, you can just return a chunk of html and stick it in ur site, very simple to use.