Search code examples
c#asp.net-mvchttp-redirectroutescontrollers

Changing route in browser MVC c#


I have a small issue and I will be glad if someone could help me.

I am creating a project from University and in the Menu I have reference to another website. I am using method Redirect in Home controller like this:

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

It's working fine but when I put my mouse on the reference(Hover) I got path from old view which I deleted, I mean:

I got:

Home/MyReference

but I want

Home/linktootherwebsite.com

Or even:

linktootherwebsite.com

Thanks for all help. Best wishes. :)


Solution

  • Then just add this to your RouteConfig.cs before the default route:

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