Reputation: 248
I define a new route in my asp.net project
routes.MapRoute(
name: "Default",
url: "{controller}.{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
and controller (lets call it TempController) that have 2 actions :
How to create a route to TempController to action CheckParameter?
Thanks for every answer!
Upvotes: 0
Views: 35
Reputation: 478
New Route
routes.MapRoute(
name: "TempCheck",
url: "{controller}/{action}/{stringParam}",
defaults: new { controller = "Temp", action="CheckParameter",stringParam= UrlParameter.Optional }
);
TempController.cs
public ActionResult CheckParameter(string stringParam){
}
Invocation
localhost:9090/temp/CheckParameter/PassAnyString
If you do not wish to add a new route you can also try this
http://localhost:9090/temp/CheckParameter?stringParam=11
In a @Url.Action would be :
@Url.Action("CheckParameter","temp", new {stringParam=11});
Upvotes: 0
Reputation: 205
Home Route For Temp:
routes.MapRoute(
name: "TempHome",
url: "{controller}.{action}",
defaults: new { controller = "Temp", action = "Index"}
);
Check Route For Temp:
routes.MapRoute(
name: "TempCheck",
url: "{controller}.{action}/{id}",
defaults: new { controller = "Temp", action = "CheckParameter", id = UrlParameter.Optional }
);
usage: http://www.website.com/temp.checkparameter/id
or you can have this:
routes.MapRoute(
name: "TempCheck",
url: "CheckSomething/{id}",
defaults: new { controller = "Temp", action = "CheckParameter", id = UrlParameter.Optional }
);
usage for id=10: http://www.website.com/CheckSomething/10
Upvotes: 1