C# 使用专用函数从重定向到路由

C# 使用专用函数从重定向到路由,c#,asp.net-mvc,C#,Asp.net Mvc,我有一个带有try..catch块的私有函数,它应该重定向到catch块中的一般错误页。问题在于,如果我执行Return redirectoroute()操作,函数将返回ViewModel类型,因此存在转换错误。此函数中是否有重定向到路由的方法,以便在捕捉块触发时显示错误页面?如果您的函数是动作结果,则您可以重定向到其他动作结果或其他控制器,例如 public ActionResult asdf() { . . . // return View(model); normally

我有一个带有
try..catch
块的私有函数,它应该重定向到
catch
块中的一般错误页。问题在于,如果我执行
Return redirectoroute()
操作,函数将返回ViewModel类型,因此存在转换错误。此函数中是否有重定向到路由的方法,以便在捕捉块触发时显示错误页面?

如果您的函数是动作结果,则您可以重定向到其他动作结果或其他控制器,例如

public ActionResult asdf()
{
    . . .

    // return View(model); normally

    return RedirectToAction("AnotherAction");

    OR

    return Redirect("/ControllerName/ActionName?QueryParameter=Value");

    OR

   string samplecontent = "<h1>For example</h1>";
   return Content(samplecontent);

}
public ActionResult asdf()
{
. . .
//返回视图(模型);通常为
返回重定向到操作(“另一个操作”);
或
返回重定向(“/ControllerName/ActionName?QueryParameter=Value”);
或
string samplecontent=“例如”;
返回内容(样本内容);
}

该函数返回的是视图模型,而不是操作结果,因此不起作用。正常!ActionResult可以有一个视图。但是如果您愿意,您可以重定向到另一个操作结果,或者发送带有
返回内容(StringValue)的内容它需要返回模型,这样调用函数的东西就可以用结果填充变量。我不想返回ActionResult