4

I'm using MVC 4.

My default route on my site is Home/Index so when the user enters the URL www.example.com it goes to that route.

Could you let me know if it is also possible to receive a parameter appended to that URL i.e. www.example.com/param? It works if I use www.example.com/Home/Index/param but that's not ideal.

I'm guessing its something I need to add to the Global.asax but I can't find examples anywhere.

1 Answer 1

3
        context.MapRoute(
            "Home_all",
            "/{*actions}",
            new { controller = "Home", action = "Index"}
        );

But be aware that route will match all urls , so you need to register it at last :) That Routing will be called like this in your Home Controller for example... Actions will be a part from the url, and you can even add some parameter in the query string

    public ActionResult Index(string actions, string id)
    {
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.