1

I have a situation where I need to pass two parameters to an action. I've been passing parameters to actions using the code below but I don't see how I pass multiple parameters. How do I do this?

 @Html.ActionLink("Add Visit", "Create", "Visit", new { id = Model.Id }, null)

BTW - ASP.NET MVC 4 RC

2 Answers 2

4

You should separate the parameters with comma, like this:

 @Html.ActionLink("Add Visit", "Create", "Visit", 
                  new { id = Model.Id, secondParameter = Model.yourValue }, null)

Check the MSDN documentation for the ActionLink method.

Hope it helps!

Sign up to request clarification or add additional context in comments.

1 Comment

@user1469655 could you please mark this(or any other) response as the answer to your question.... at least if you were able to solve your problem.
0

I add from CodePlex called T4MVC. This turns all your strings into a method call by using a combination of T4 templates and partial classes. It will allow you to turn your ActionLink methods into a syntax checked method call.

@Html.ActionLink("Add Visit", "Create", "Visit", new { id = Model.Id }, null)

would be turned into

@Html.ActionLink("Add Visit", MVC.Visit.Create(Model.Id))

and

@Html.ActionLink("Add Visit", "Create", "Visit", new { id = Model.Id, Param2 = "Param2", Param3= "Param3Value" }, null)
@Html.ActionLink("Add Visit", MVC.Visit.Create(Model.Id, "Param2", "Param3Value"))

Its a life saver when you turn on compiled views.

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.