如何从另一个控制器重定向到索引? [英] How to redirect to Index from another controller?

查看:113
本文介绍了如何从另一个控制器重定向到索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找通过努力找到一些方式来重定向到另一个控制器中的首页视图。

 公众的ActionResult指数()
{
     ApplicationController的视图模型=新的ApplicationController();
     返回RedirectToAction(指数,视图模型);
}

这是我尝试过现在。现在,code我是给有一个 ActionLink的的链接,我需要重定向过的页面。

  @ Html.ActionLink(巴利应用程序,../应用程序)


解决方案

使用了作为控制器的名字太重载...

 返回RedirectToAction(指数,myController的);

  @ Html.ActionLink(链接名称,索引,myController的,NULL,NULL)

I have been looking through trying to find some way to redirect to an Index view from another controller.

public ActionResult Index()
{                
     ApplicationController viewModel = new ApplicationController();
     return RedirectToAction("Index", viewModel);
}

This is what I tried right now. Now the code I was given to has a ActionLink that links to the page I need to Redirect too.

@Html.ActionLink("Bally Applications","../Application")

解决方案

Use the overloads that take the controller name too...

return RedirectToAction("Index", "MyController");

and

@Html.ActionLink("Link Name","Index", "MyController", null, null)

这篇关于如何从另一个控制器重定向到索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆