dimanche 28 juin 2015

How to enable use of both named and unnamed url parameters in Asp.Net MVC

Most likely a very basic question, but still: In an ASP.Net MVC application, how can I enable a controller to respond to URLs that have either named or unnamed URL parameters.

With the following controller:

[Route("test/display/{scaleid}")]
public ActionResult Display(int scaleid)
{
    return View();
}

I try two URL requests - the first one works, the second one (where I specify the parameter name), doesn't work. Why is this?

http://localhost:43524/Test/Display/11
http://localhost:43524/Test/Display/?scaleid=11

Aucun commentaire:

Enregistrer un commentaire