我正在尝试重定向到视图并继续在问题标题中发布错误.
在断点测试期间,通过代码iv的第一位的代码放在设置消息和设置异常之下.在返回重定向后继续显示下一页显示如下.

向ErrorController和错误模型添加断点我发现代码永远不会到达那里.
我想要发布的视图是一个错误页面.这是代码,以帮助您看到问题.
RedirectToAction:
string message;
message = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";
return RedirectToAction("Error", "Error", new { ex = ex.ToString(), message = message});
Run Code Online (Sandbox Code Playgroud)
我的ErrorController中的操作:
public ActionResult Error(string ex, string message)
{
ViewBag.Message = "Error";
return View(new ErrorModel(ex, message));
}
Run Code Online (Sandbox Code Playgroud)
我的错误模型:
namespace MvcResComm.Models
{
public class ErrorModel
{
public string ex { get; set; }
public string message { get; set; }
public ErrorModel(string ex, string message)
{
this.ex = ex;
this.message = message;
}
}
}
Run Code Online (Sandbox Code Playgroud)
the*_*erm 16
在web.config项目的根目录下,在system.web节点下:
<system.web>
<httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
...
Run Code Online (Sandbox Code Playgroud)
另外,我不得不在system.webServer节点下添加它,或者我的长查询字符串出现了安全性错误:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="9999" />
</requestFiltering>
</security>
...
Run Code Online (Sandbox Code Playgroud)
你为什么不使用TempData,它就是用来做这样的事情的。例如:
TempData["ErrorMessage"] = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";
Run Code Online (Sandbox Code Playgroud)
检查此链接。
编辑
像这样传递您的异常消息:
TempData["Error"] = ex.Message();
TempData["ErrorMessage"] = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";
return RedirectToAction("Error", "Error");
Run Code Online (Sandbox Code Playgroud)
然后只需从您的 访问它ErrorController,例如:
public ActionResult Error(string ex, string message)
{
var error = (string)TempData["Error"];
// do other magic ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28618 次 |
| 最近记录: |