ASP.NET MVC 3 - 重定向到另一个动作 [英] ASP.NET MVC 3 - redirect to another action
本文介绍了ASP.NET MVC 3 - 重定向到另一个动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将 Home 控制器的 Index 动作重定向到另一个控制器的动作,而不是别的.我的代码是这样的:
I want to redirect the Index action of the Home controller to another controller's action and nothing else. My code is thus:
public void Index()
{
//All we want to do is redirect to the class selection page
RedirectToAction("SelectClasses", "Registration");
}
现在,这只是加载一个 0 kB 的空白页面,什么也不做.我有一种感觉,它与 void 返回类型有关,但我不知道还能将其更改为什么.这里有什么问题?
Right now, this just loads a 0 kB blank page and does nothing. I have a feeling it has something to do with that void return type, but I don't know what else to change it to. What's the issue here?
推荐答案
你的方法需要返回一个 ActionResult
类型:
Your method needs to return a ActionResult
type:
public ActionResult Index()
{
//All we want to do is redirect to the class selection page
return RedirectToAction("SelectClasses", "Registration");
}
这篇关于ASP.NET MVC 3 - 重定向到另一个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文