I 'm doing a dot net project (MVC) in which I want to pass integers (hard coded university ids) from view to Controller. In view I 'm doing
<a href="/Admin/applied/1">PU</a>
<a href="/Admin/applied/2">UET</a>
<a href="/Admin/applied/3">GC</a>
where admin is the CONTROLLER & applied is ACTION METHOD
in ACTION METHOD (applied in Admin)
public ActionResult applied(string uniId)
{
Processing of admissions on the basis of uniId
}
but when I 'm compiling this , uniId contains NULL instead of actual integer passed by <a href="/Admin/applied/1">PU</a> etc.
Kindly help me out
ASP.NET MVC will only provide the value if the parameter is named id. You have to options. First is renaming the parameter:
public ActionResult applied(string id)
{
Processing of admissions on the basis of uniId
}
Second is creating a new route in RouteConfig above the default route:
routes.MapRoute(
"Applied", // Route name
"Admin/applied/{uniId}", // URL with parameters
new { controller = "Admin", action = "applied" } // Parameter defaults
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With