Reputation: 3717
<a href="@Url.Action("UpdateCase", "Receptionist", new { id = @Model[SrNo].Patient_ID })" class="btn btn-danger">Edit</a>
In a href, I've pass id as parameter. so when I redirected to action I have following url
But I want id word visible in url.
RouteConfig
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
If I change parameter name rather than id, it is working. only id is not visible in url
UpdateCase Action:
[Authorize]
[HttpGet]
public ActionResult UpdateCase(Int64 id)
{
}
Upvotes: 4
Views: 490
Reputation: 24579
One of possible solution is change your route config to
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{param}",
defaults: new { controller = "Home", action = "Index", param = UrlParameter.Optional }
);
In that case you won't have a parameter with name id
in the route table, so Url.Action
can't use it and as a result you wil get expected url.
But be careful and check others actions
Upvotes: 3
Reputation: 9281
Question marks are added when the parameter is not specified in the URL, so removing the {id}
from your route will force the question mark to be added in the URL.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Upvotes: 0