I have a controller method that looks like
public ViewResult Index(string id, string participant="", string flagged = "")
id is a route value in my global.asax for this controller. I want to pass in the other values as regular arguments so the link would look like
.../controller/Index/id?participant=yes&flagged=no
Is there a way to generate a link like this using Razor script in MVC 3?
You could pass all parameters in the
routeValuesargument of the ActionLink method:Assuming default routing setup this will generate:
UPDATE:
To further elaborate on the comment you have posted, if the ActionLink generated an url with
Length=6for example this means that you have used the wrong overload. For example this is wrong:It is obvious why this is wrong from the comments I’ve put along each parameter name. So make sure you are carefully reading the Intellisense (if you are lucky enough to have Intellisense working in Razor :-)) to pick the correct overload of the helper methods.
The correct overload in the case you want to specify a controller name is the following:
Notice the
nullthat is passed as last argument. That’s what corresponds to thehtmlAttributesparameter.