【问题标题】:Why PartialView is opening in new window with post action?为什么 PartialView 在新窗口中打开并发布操作?
【发布时间】:2013-11-20 08:39:25
【问题描述】:

我有两种操作方法。 Get 方法返回部分视图,用户必须填写一些表单。

当我按下这个表单上的按钮时调用 Post 方法,它也返回一个局部视图。但是 post 方法总是在新窗口中打开部分视图。

但我需要 post 方法来加载像 PARTIAL 这样的部分视图,而不是在新窗口中

你有什么想法吗?

[HttpGet]
public PartialViewResult EditProfile(int freelancerId)

    FreelancerProfile freelancerProfile = new FreelancerProfile();

    return PartialView(freelancerProfile); // EditProfile is opening in the part of window. it's ok.
}

[HttpPost]
public PartialViewResult EditProfile(FreelancerProfile freelancerProfile)
{
    repository.SaveProfileChangesFreelancer(freelancerProfile);

    return PartialView("EditProfile", freelancerProfile); //EditProfile is opening in the new window. it's trouble
}

【问题讨论】:

  • 您应该通过 javascript 调用 PartialViewResult 发布方法,并使用 javascript 或 jquery 在您的页面中呈现结果

标签: asp.net-mvc asp.net-mvc-4 http-post asp.net-mvc-partialview


【解决方案1】:

但是 post 方法总是在新窗口中打开部分视图。

这不是你的控制器可以做的事情,它必须在调用你的局部视图的 HTML 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-09
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多