gpt4 book ai didi

c# - Actionlink 没有在 asp.net mvc View 中获取 Bootstrap 按钮类

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:49 24 4
gpt4 key购买 nike

您好,有人可以快速浏览一下附件,看看为什么按钮没有正确选择 Bootstrap 类。

有问题的 Actionlink 项目位于 View 的最后。

我曾尝试将@section 脚本部分移动到页面的不同部分,但没有任何区别。

谢谢约翰

@model IEnumerable<IWA_Mileage_Tracker_Demo.Models.Journey>

@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}


<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.StartAddress)
</th>
<th>
@Html.DisplayNameFor(model => model.FinishAddress)
</th>
<th>
@Html.DisplayNameFor(model => model.DateofJourney)
</th>
<th>
@Html.DisplayNameFor(model => model.distance)
</th>
<th>
@Html.DisplayNameFor(model => model.ReasonForJourney)
</th>

</tr>

@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.StartAddress)
</td>
<td>
@Html.DisplayFor(modelItem => item.FinishAddress)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateofJourney)
</td>
<td>
@Html.DisplayFor(modelItem => item.distance)
</td>

<td>
@Html.DisplayFor(modelItem => item.ReasonForJourney)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}

</table>

<div class="col-md-6">

@Html.ActionLink("Add a new journey", "Create", new {@class = "btn btn-default"})
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

最佳答案

Html.ActionLink 的第三个参数代表routeValues。如果你想添加 html 属性(和一些特定的类),你必须使用另一个重载:

@Html.ActionLink(string linkText, string actionName, object routeValues, object htmlAttributes)

对于您的情况,您可以为 routeValues 传递空对象或 null,它将是:

@Html.ActionLink("Add a new journey", "Create", null, new { @class = "btn btn-default"})

关于c# - Actionlink 没有在 asp.net mvc View 中获取 Bootstrap 按钮类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32278344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com