I have a ShowController that with the following ActionResult function returns data for a view.
public ActionResult Details(int id)
{
var item = from s in db.Shows.Where(si => si.ShowId == id) select s;
return View(item);
}
The code for the details view is as follows:
<div id = "browseShow" class = "show">
<ul>
@foreach (var item in Model)
{
<li>
<h2>@item.Title</h2>
</li>
<li class = "lihead">
Directed by
@Html.ActionLink((string)item.Director.Name, "Index", "Director", new { searchString = item.Director.Name }, null)
</li>
<li>
<i>@item.Synopsis</i>
</li>
<li class = "lihead">
Price per ticket £
@item.Price
</li>
}
</ul>
</div>
You will notice a @Html.ActionLink that access a function within another controller, the DirectorController. I am trying to add a button to my page using the following code:
<p class = "button"> <!-- The text, Name of method, Name of controller-->
@foreach (var item in Model)
{
@Html.ActionLink("Check Availability", "CheckAvail", "Booking", new { id = item.ShowId })
}
</p>
I want this code to take the ShowId var into a different controller, the BookingController but my application keeps looking at this controller the StoreController and I don't know why. Can anyone please help?
SamuelCampbe...
Member
106 Points
103 Posts
Problem with @HtmlActionLink
Apr 24, 2012 11:52 AM|LINK
I have a ShowController that with the following ActionResult function returns data for a view.
public ActionResult Details(int id) { var item = from s in db.Shows.Where(si => si.ShowId == id) select s; return View(item); }The code for the details view is as follows:
<div id = "browseShow" class = "show"> <ul> @foreach (var item in Model) { <li> <h2>@item.Title</h2> </li> <li class = "lihead"> Directed by @Html.ActionLink((string)item.Director.Name, "Index", "Director", new { searchString = item.Director.Name }, null) </li> <li> <i>@item.Synopsis</i> </li> <li class = "lihead"> Price per ticket £ @item.Price </li> } </ul> </div>You will notice a @Html.ActionLink that access a function within another controller, the DirectorController. I am trying to add a button to my page using the following code:
<p class = "button"> <!-- The text, Name of method, Name of controller--> @foreach (var item in Model) { @Html.ActionLink("Check Availability", "CheckAvail", "Booking", new { id = item.ShowId }) } </p>I want this code to take the ShowId var into a different controller, the BookingController but my application keeps looking at this controller the StoreController and I don't know why. Can anyone please help?
JohnLocke
Contributor
3216 Points
710 Posts
Re: Problem with @HtmlActionLink
Apr 24, 2012 02:29 PM|LINK
The correct overload is (string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
Your incorrect overload points to (string linkText, string actionName, object routeValues, object htmlAttributes)
The overload you want to use requires 5 arguments, but you only pass in 4. It should be:
@Html.ActionLink("Check Availability", "CheckAvail", "Booking", new { id = item.ShowId }, null)