2016-05-17 6 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"); 
    } 

それはそのビューに私をリダイレクトしても一部のGoogleをしたと私はJavascript自体にこの事を持っているとOnSuccessオプションを使用してURLを呼び出すことがわかっていません。私のシナリオでjavascriptを使用してポストバックを行う方法。 また、投稿する前にコードが変更されているため、コードを参照しないでください。私はちょうど更新後に起こるようにリダイレクトしたい。

+0

アヤックスの全体の目的は、同じページに滞在することです、そしてあなたがリダイレクトするときにデータを投稿するAJAXを使用すると、ちょうど無意味であるあなたに感謝@Igor – Steve

+0

。通常の送信を行い、コードを保存してパフォーマンスを向上させます。 –

+0

これはありがたいです! – Steve

答えて

1

Ajaxの成功のために、JavaScript関数の使用を更新してください。

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

あなたのinput.iありがとう、私の答えを得たが、まだ他のオプションのためにこれを答えとしてマーク:P – Steve

関連する問題