2016-05-17 20 views
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回發。 也不要在發佈前修改代碼。我只是想更新後發生重定向。

+0

謝謝@Igor – Steve

+0

AJAX的全部目的是留在同一頁上,並使用Ajax時要重定向到發佈的數據僅僅是毫無意義的。做一個正常的提交併保存一些代碼並提高性能。 –

+0

明白了..謝謝! – Steve

回答

1

請更新您的javascript函數使用Ajax的成功。

function UpdateData() { 

var testData= $("#hdn_EditdsVal").val(); 
var feature= $("#hdn_EditdsVal").val(); 
}; 
$.ajax({ 
    url: '@(Url.Action("UpdatePlanFeatVal", "SuperAdmin"))', 
    type: "POST", 
    dataType: "json", 
    data: { testData: testData, feature: feature },  
    contentType: "application/json", 
    success: function (result) { 
     window.location.href = '@Url.Action("Action", "Controller")'; 
    }, 
    error: function (err) { 

    } 
}); 
} 
+0

謝謝你的輸入。我得到了我的答案,但仍然標記爲答案,因爲沒有其他選項:P – Steve

相關問題