在浏览器MVC中更改路由c#

时间:2016-05-10 10:27:10

标签: c# asp.net-mvc redirect routing controllers

我有一个小问题,如果有人可以帮助我,我会很高兴。

我正在从大学创建一个项目,在菜单中我引用了另一个网站。我在Home控制器中使用方法Redirect,如下所示:

    public ActionResult MyReference()
    {
        ViewBag.Current = "MyReference";
        return Redirect("linktootherwebsite.com");
    }

它工作正常但是当我把鼠标放在引用上时(Hover)我从旧视图中找到了我删除的路径,我的意思是:

我得到了:

Home/MyReference

但我想要

Home/linktootherwebsite.com

甚至:

linktootherwebsite.com

感谢您的帮助。 最好的祝愿。 :)

1 个答案:

答案 0 :(得分:1)

然后将此添加到您的RouteConfig.cs 之前默认路线:

routes.MapRoute(
    name: "whatever",
    url: "Home/linktootherwebsite.com",
    defaults: new
    {
        controller = "Home",
        action = "MyReference",
    }
);