C# ASP.NET MVC 3-重定向到其他操作
我想将主控制器的索引操作重定向到另一个控制器的操作,而不是其他操作。因此,我的代码是:C# ASP.NET MVC 3-重定向到其他操作,c#,asp.net-mvc,redirect,C#,Asp.net Mvc,Redirect,我想将主控制器的索引操作重定向到另一个控制器的操作,而不是其他操作。因此,我的代码是: public void Index() { //All we want to do is redirect to the class selection page RedirectToAction("SelectClasses", "Registration"); } 现在,这只是加载一个0 kB的空白页,什么也不做。我有一种感觉,它与无效返回类型有关
public void Index()
{
//All we want to do is redirect to the class selection page
RedirectToAction("SelectClasses", "Registration");
}
现在,这只是加载一个0 kB的空白页,什么也不做。我有一种感觉,它与无效返回类型有关,但我不知道还有什么可以改变它。这里有什么问题?您需要返回
重定向到操作的结果应该,而不是Void您的方法需要返回操作结果
类型:
public ActionResult Index()
{
//All we want to do is redirect to the class selection page
return RedirectToAction("SelectClasses", "Registration");
}
您必须编写此代码,而不是返回视图();:
如果您提供一些上下文和解释来说明为什么这会起作用,会有所帮助。如果您需要传递一些参数:return RedirectToAction(“ActionName”,“ControllerName”,new{id=99,name=“sample”});
return RedirectToAction("ActionName", "ControllerName");
return RedirectToAction("ActionName", "ControllerName");