2016-05-06 80 views
1

我正在嘗試將用戶從控制器上的某個方法重定向到另一個視圖,但無論如何我都無法使其工作。我究竟做錯了什麼?這是我的代碼:將用戶從控制器重定向到另一個視圖MVC

  public ActionResult SubmitReport(string JsonStringSend) 
     { 
      dynamic JSend = JObject.Parse(JsonStringSend); 
      var schema = JsonSchema4.FromType<ReportItem>(); 
      var schemaData = schema.ToJson(); 
      var errors = schema.Validate(JSend.JsonString); 
      schema = JsonSchema4.FromJson(schemaData); 


      //Check for errors and show them if they exist 
      if (errors.Count > 0) 
      { 
       //JSchema schema = JSchema.Parse(schema); 
       foreach (var error in errors) 
        Console.WriteLine(error.Path + ": " + error.Kind); 

       //JObject JsonString = JObject.Parse(JsonObj.JsonString.ToString()); 
       //JObject JsonStringSent = JObject.Parse(JsonStringSend); 

      } 
      else 
      { 
       return Redirect("/Admin/Reporting/ReportManagement"); 
      } 
      return View(); 
     } 

它從不重定向。我甚至試過這些:

Response.Redirect(Url.Action("/ReportManagement")); 
RedirectToRoute(new { contoller = "ReportManagement", action = "Reporting" }); 
return RedirectToRoute(new { contoller = "Reporting", action = "ReportManagement" }); 
return RedirectToAction("ReportManagement"); 

似乎沒有重定向,什麼給?

+0

如果您在調試模式下單步執行代碼,會發生什麼情況? – Cortright

+0

什麼,當我到'返回重定向(「/管理/報告/ ReportManagement」);'它只是繼續步 –

+0

你目前的網址是什麼? – Cortright

回答

4

您不重定向到視圖,而是重定向到動作或路由。如果我正確地分析你嘗試,你有這樣的路徑,:

return Redirect("/Admin/Reporting/ReportManagement") 

應該

return RedirectToAction("Reporting", "ReportManagement", new { area="Admin" }) 

這是假定報告行動上ReportManagementController類的管理區域。

1

試試這個,應該是工作:

return RedirectToAction("yourAnotherActionName","yourAnotherControllerName"); //It's very simply;) 

我測試過它!

相關問題