@ Html.ActionLink一部作品和一个不 [英] @Html.ActionLink one works and one does not
问题描述
我有两个@ Html.ActionLink的一件作品,一个没有,我想不通为什么?
I have two @Html.ActionLink's one works and one does not and I cannot figure out why?
他们都是在同一个控制器内:StoreController和不同的控制器中同时调用ActionResults,这是一个工作,并呼吁处长类中的索引功能之一:
They are both within the same controller: StoreController and both call ActionResults within different controllers, this is the one that works and calls the Index function within the Director Class:
<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>
}
这是一个不工作之一:
@foreach (var item in Model) {
@Html.ActionLink("Check Availability", "CheckAvail", "Booking", new { id = item.ShowId })
}
这一个StoreController内时,我想它来调用BookingController内CheckAvail函数调用。然而,当我修改它如此确实工作:
This one calls within the StoreController when I want it to call the CheckAvail function within the BookingController. However it does work when I amend it as so:
@foreach (var item in Model) {
@Html.ActionLink("Check Availability", "CheckAvail", "Booking")}
但我需要它通过ShowId采取功能???
But I need it to take through the ShowId to the function???
推荐答案
使用像这样
@Html.ActionLink("Check Availability", "CheckAvail", "Booking", new { @id = item.ShowId },null)
据使用此重载
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
string controllerName,
Object routeValues,
Object htmlAttributes
)
http://msdn.microsoft.com/en-us/library/ dd504972.aspx
的最后一个参数是HTML属性。如果你有一些HTML属性附加伤害传递,你通过它的存在,而不是空
the last parameter is the HTML attribute. If you have some HTML atribute to pass, you pass it there instead of null
@Html.ActionLink("Check Availability", "CheckAvail", "Booking", new { @id = item.ShowId },new { @class="myCssClass"} )
这篇关于@ Html.ActionLink一部作品和一个不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!