如何使以下代码成为链接列表而不是按钮列表?
@foreach (var item in @Model)
{
using (Html.BeginForm(new { action = "GetL", controller = "L" }))
{
<input name="fileLocation" type="submit" value="@item" />
}
}
答案 0 :(得分:1)
@foreach (var item in @Model)
{
using (Html.BeginForm(new { action = "GetL", controller = "L" }))
{
<a name="fileLocation" href="@item">@item</a>
}
}
答案 1 :(得分:0)
您可以使用 Html.ActionLink 辅助方法生成锚标记
@foreach (var item in @Model)
{
using (Html.BeginForm(new { action = "GetL", controller = "L" }))
{
@Html.ActionLink(item,"yourAction","YourController")
}
}
如果要将一些参数(例如:Id)传递给Action方法,可以使用this覆盖
来执行此操作@Html.ActionLink(item,"yourAction","YourController",
new { @id="someVal"} ,null)