Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
how can we get Name from this URL http://www.myurl.com/Name. Name is Changed everytime, so i am redirecting to default Action method by using Routing in MVC4
i just need entered Name from this URL in my Action Method.

C#
routes.MapRoute(
       name: "Default",
         url: "{Name}",
        defaults: new { controller = "Home", action = "DefaultURL" }
        );


how can i get entered name in my DefaultURL Action Method

C#
public ActionResult DefaultURL()
       {
       // i need name here

       }


Kindly help.
Posted
Updated 17-Feb-14 22:04pm
v2

1 solution

i just got it.
By Passing Parameter name as Name to my Action Method


C#
 routes.MapRoute(
            name: "Default",
              url: "{Name}",
             defaults: new { controller = "Home", action = "DefaultURL" }
             );

public ActionResult DefaultURL(string Name)  // parameter should be same as url:
        {
        // i need name here
           
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900