How can I simplify the url to http://localhost:51675/Prescriptions/Create/12 instead of http://localhost:51675/Prescriptions/Create?AssessmentID=12.
currently i am using this code
@Html.ActionLink("Edit", "Edit", new { id = Model.PrescriptionID })
as asked on Facebook group
You can do this by following methods
Method 1:
1. Go to App_Start folder then RouteConfig.Cs
file
2. Add new Route in it , like this
routes.MapRoute(
name:"UniqueRouteName",
Url:"{controller}/{action}/{id}",//this is url pattern which we want, in your case it would be "/Edit/Edit/12"
defaults:new{controller="Edit",action="Edit",id=UrlParameter.Optional}
);
3. Build your solution and you are done.
Note: This Should be placed before Default routing
Method 2:
[Route(“Edit/{id:int}”)]
public ActionResult Edit(int id)
{
//do something
return View();
}
?
RegisterRoute
Methodroutes.MapMvcAttributeRoutes();?
That's it, hope this helps
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly