我有桌子视图
这是一些代码
<tr style="background: #d1d3d4">
<th></th>
<th style="font-size: 20px; text-align: center;">
@Html.DisplayNameFor(model => model.CompanyName)
</th>
<th style="font-size: 20px; text-align: center;">
@Html.DisplayNameFor(model => model.Vacancies.FirstOrDefault().VacancyName)
</th>
我需要点击<th>
文字转到另一个视图。我怎么能这样做?
答案 0 :(得分:0)
你想要的是HTML锚标记(<a>
)。在.NET MVC中,您可以使用@Url.Action()
帮助程序创建指向控制器操作的链接。
它看起来像这样:
<th style="font-size: 20px; text-align: center;">
<a href="@Url.Action("Action", "Controller")">@Html.DisplayNameFor(model => model.CompanyName)</a>
</th>
显然,您将使用您的操作名称替换“Action”,并使用您的控制器名称替换“Controller”。
答案 1 :(得分:0)
您可以使用Html.ActionLink
,我认为您的表格标题CompanyName
只是呈现为Company Name
。如果没有,并且您显示的是其他名称..那么请使用zgood的答案。
<tr style="background: #d1d3d4">
<th></th>
<th style="font-size: 20px; text-align: center;">
@Html.ActionLink("Company Name", "Action", "Controller")
</th>
<th style="font-size: 20px; text-align: center;">
@Html.DisplayNameFor(model => model.Vacancies.FirstOrDefault().VacancyName)
</th>
希望这有帮助。