开发者

Load MVC PartialView via Ajax

开发者 https://www.devze.com 2023-04-01 03:26 出处:网络
In my View I have: $.ajax({ url: \'/Profile/TryToGetPersonalInfo\', type: \'post\', success: function (outData) {

In my View I have:

$.ajax({
    url: '/Profile/TryToGetPersonalInfo',
    type: 'post',
    success: function (outData) {
        if (outData.loggedIn == true) {
            $('#PersonalInfoData').load(outData.data);
        }
    }
});

And in my Controller I have:

[HttpGet]
private ActionResult PersonalInfo()
{
    return PartialView();
}

[HttpPost]
public JsonResult TryToGetPersonalInfo()
{
    // loggedIn is temporary
    return Json( new { loggedIn = true, data = this.PersonalInfo() } );
}

How come .load() doesn't do the job? I have also tried .html(), b开发者_JS百科ut still, no luck.

Please note that I really want to keep this form (having ProfileInfo() as private), and TryToGetProfileInfo() as post, cause I'm using validation tokens.


You are returning a Json object. You need to return html. In similar cases, I declare the action return type as an ActionResult and return a partial view.

0

精彩评论

暂无评论...
验证码 换一张
取 消