【发布时间】:2016-09-13 08:31:03
【问题描述】:
下面是我的 Javascript 函数,它会在点击更新按钮时进行更新。
function UpdateData() {
var obj = {
"testData": $("#hdn_EditdsVal").val(),
"feature": $("#hdn_EditdsVal").val()
};
$.ajax({
url: '@(Url.Action("UpdatePlanFeatVal", "SuperAdmin"))',
type: "POST",
dataType: "json",
data: JSON.stringify(obj),
contentType: "application/json",
success: function (result) {
// want to redirect the user using ControllerName/ActionMethod
},
error: function (err) {
}
});
}
还有我的控制器
public ActionResult UpdatePlanFeatVal(string testData,string feature)
{
var cmd = (object)null;
testData = testData.Trim();
string[] words = testData.Split(':');
XDocument _xdoc = new XDocument(new XElement("Pricing"));
foreach (string word in words)
{
if (!string.IsNullOrEmpty(word))
{
string[] wor = word.Split('_');
_xdoc.Root.Add(
new XElement("row",
new XElement("FeatureId", wor[1]),
new XElement("PlanId", wor[2]),
new XElement("Unit", wor[3])
));
}
}
using (StoredProcedureContext sc = new StoredProcedureContext())
{
cmd = sc.EditPricing(_xdoc);
}
return View("ManageSubscriptionPlan");
}
它没有将我重定向到那个视图,也做了一些谷歌,发现我必须在 Javascript 本身中使用这个东西并使用 OnSuccess 选项调用 url。知道如何在我的场景中使用 javascript 进行回发。
并且也不要浏览代码,因为它在发布之前已被修改。我只想在更新后进行重定向。
【问题讨论】:
-
ajax 的全部目的是保持在同一页面上,当您想要重定向时使用 ajax 发布数据是没有意义的。进行正常的提交并为自己节省一些代码并提高性能。
标签: javascript ajax asp.net-mvc