Passing integer values ​​from view to controller (mvc) via href

I am making a net net (MVC) project where I want to pass integers (hardcoded university IDs) from a view to a Controller. In the mind of what i do

<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 and the METHOD OF ACTION is applied

in METHOD OF ACTION (used in Admin)

public ActionResult applied(string uniId)
{
    Processing of admissions on the basis of uniId
}

      

but when I compile this uniId contains NULL instead of the actual integer passed in <a href="/Admin/applied/1">PU</a>

etc. Please help me

+3


source to share


1 answer


ASP.NET MVC will only provide a value if the parameter has a name id

. You have options. First, rename the parameter:

public ActionResult applied(string id)
{
    Processing of admissions on the basis of uniId
}

      



Second creation of 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
        );

      

+3


source







All Articles