3

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

5
  • 2
    Do you have a specific route defined for this action that has a parameter named uniID? If not create one or change your method to public ActionResult applied(string id) to match the default route Commented May 19, 2015 at 10:56
  • Sorry I didn't get your point, my method is already public ActionResult applied(string uniId), what route define? Commented May 19, 2015 at 10:59
  • Show your routes! And its not (string id) it (string uniId). Change uniId to id Commented May 19, 2015 at 11:00
  • Admin{Controller}/Applied{actionMethod} what do you mean by "ROUTES"? Commented May 19, 2015 at 11:05
  • The routes as defined in the route.config.cs file Commented May 19, 2015 at 11:12

1 Answer 1

3

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
        );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.