将用户从控制器重定向到另一个视图 MVC
Redirect user from controller to another view 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");
似乎没有重定向,是什么原因?
您不会重定向到视图,而是重定向到操作或路由。如果我正确地解析了你正在尝试的路径,那么你有这个:
return Redirect("/Admin/Reporting/ReportManagement")
应该是
return RedirectToAction("Reporting", "ReportManagement", new { area="Admin" })
这假定 Reporting 对 ReportManagementController class 的 Admin 操作]面积
试试这个,应该可以:
return RedirectToAction("yourAnotherActionName","yourAnotherControllerName"); //It's very simply;)
我测试过了!
我正在尝试将用户从控制器上的方法重定向到另一个视图,但无论我做什么都无法正常工作。我究竟做错了什么?这是我的代码:
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");
似乎没有重定向,是什么原因?
您不会重定向到视图,而是重定向到操作或路由。如果我正确地解析了你正在尝试的路径,那么你有这个:
return Redirect("/Admin/Reporting/ReportManagement")
应该是
return RedirectToAction("Reporting", "ReportManagement", new { area="Admin" })
这假定 Reporting 对 ReportManagementController class 的 Admin 操作]面积
试试这个,应该可以:
return RedirectToAction("yourAnotherActionName","yourAnotherControllerName"); //It's very simply;)
我测试过了!