lundi 4 janvier 2016

Parameters in MVC not being correctly passed into the view from routing

I'm teaching myself MVC and have an issue with routing correctly

I have a controller named "ClipsController" and 1 view inside with the name "Index" (boring, i know)

I have my routeconfig file configured with the following route:

routes.MapRoute(
    "Clips",
    "Clips/{id}",
    new { controller = "Clips", action = "Index", id = urlparameters.Optional }
);

which is Before the "Default" route. When i go to /Clips/ExampleID it does hit the correct route, and does start the Index action in the Clips controller. What i'm having trouble with is the parameter 'ID' fails to pass through into the Index page, but i end up on the index action of the Clips controller, with the URL http://ift.tt/1OHOSxv

I attempt to get the ID parameter with

httpcontext.current.request.querystring["id"]

which always returns a null. My actionresult in the controller is as follows:

public ActionResult Index(string id)
{
    return view()
}

To reiterate, I'm not able to see the querystring id on the index view, even though the URL does the correct route, and the actionresult in the controller is to my kowledge correct. If i have done something critically wrong or you need more information please let me know, Thanks.

Aucun commentaire:

Enregistrer un commentaire