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.
You need to use the overload that accepts parameters for route values. See the overloaded method
ActionLink()here.