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