3

In the application that I am trying to make, I have a menu in my view as below:

<ul id="menu">
    <li>@Html.ActionLink("Create Project", "Display", "CreateDisplay")</li>
    <li>@Html.ActionLink("Open", "About", "Home")</li>
</ul>

where CreateDisplay is the name of a controller and Display is a method in that controller which will call another view.

But, I want the Display method to accept certain parameters like username of the person. In the current view, I have obtained the username as @ViewData["UserName"]

But I am not able to pass these values using ActionLink. I tried passing the parameters as

<li>@Html.ActionLink("Create Project", "Display?UserName="+@ViewData["UserName"], "CreateDisplay")</li>

but received an exception.

Please suggest some ways of doing this.

Thank you very much in advance.

1 Answer 1

2

You need to use the overload that accepts parameters for route values. See the overloaded method ActionLink() here.

@Html.ActionLink(
    "Click me!",
    "Display",
    "CreateDisplay",
    new { UserName = "SetYourValHere" },
    null);
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.