0
以下是我的Javascript函數,它將更新點擊更新按鈕。如何通過在特定控制器和動作上使用Ajax調用來重定向用戶
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 (StoreProcedureContext sc = new StoreProcedureContext())
{
cmd = sc.EditPricing(_xdoc);
}
return View("ManageSubscriptionPlan");
}
這不是我重定向到該視圖,也做了一些谷歌,發現我有這個東西在Javascript本身,並呼籲使用OnSuccess
選項的URL。任何想法如何在我的場景中使用JavaScript回發。 也不要在發佈前修改代碼。我只是想更新後發生重定向。
謝謝@Igor – Steve
AJAX的全部目的是留在同一頁上,並使用Ajax時要重定向到發佈的數據僅僅是毫無意義的。做一個正常的提交併保存一些代碼並提高性能。 –
明白了..謝謝! – Steve