【问题标题】:String return function redirect to other page in Asp.Net MVC字符串返回函数重定向到 Asp.Net MVC 中的其他页面
【发布时间】:2013-03-26 12:17:49
【问题描述】:

我有一个从该函数返回字符串值的函数。下面显示了我的一些代码

<code>
public string MainPane()
{
 if (Request.Cookies["Cookie"] != null)
 {
  try
  {
    //DO Something code here
  }
  catch (Exception ex)
  {

  }
  return("");
}
else
{
  //I need to redirect from here when cookie value is null
}
</code>

谢谢,

尼拉夫·帕里克


这是我的 asp.net MVC 应用程序

Response.Redirect("Index"); 

此功能不可用。我试过了

RedirectToAction("Action Name","Controller Name"); 

但是函数返回字符串值并且 RedirectToAction 不返回字符串。

谢谢,尼拉夫

【问题讨论】:

  • 问题是什么?

标签: string function redirect output


【解决方案1】:

你可以使用:

Response.Redirect("Index");

它会重定向你而不需要你返回一个 ActionResult。

【讨论】:

    猜你喜欢
    • 2011-04-09
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    相关资源
    最近更新 更多