【发布时间】:2017-08-16 15:49:52
【问题描述】:
我有一个视图 UserInformation,我在其中填写了一些与用户相关的信息,并使用 ajax 帖子将这些信息发布到另一个视图“AnotherView”。
现在我想在动作方法“AnotherView”中获取这些输入,并使用一些数据模型加载视图“AnotherView”。
当我从视图 UserInformation 到操作方法 "AnotherView" 执行 Ajax Post 时,它会执行操作方法 "AnotherView",但它仍然显示视图 UserInformation
从视图 UserInformation
调用 Ajax$.ajax({
url: '/somecontroller/AnotherView/',
data: {
name: $.trim($('#mgr').val()),
id: $('#id').val(),
email: $.trim($('#hdnMgrmail').val())
},
cache: false,
type: "POST",
dataType: "html",
success: function (data,
textStatus, XMLHttpRequest) {
alert('ok');
}
});
[HttpPost]
public ActionResult AnotherView(few parametrs that is coming here)
{
//create model using input params
return View(with some model);
}
【问题讨论】:
-
您需要在成功回调中将
AnotherView()方法返回的部分视图添加到 DOM - 例如$(someElement).html(data); -
你的success函数中的data变量是否不包含AnotherView的HTML内容?您需要做的就是将此内容放在您需要的地方。
-
我必须加载完整视图而不是部分视图
-
那就不要使用ajax了!
-
Ajax.BeginForm()只是$.ajax()的一个包装器。如果您想显示不同的视图,请进行正常的提交和重定向。
标签: jquery asp.net ajax asp.net-mvc asp.net-mvc-4