2015-08-28 29 views
1

嗨,有人可以快速查看附件,看看为什么按钮没有正确拾取引导类。动作链接没有拿起在asp.net mvc视图中的引导按钮类

问题中的Actionlink项目位于视图的最后。

我已经尝试将@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") 
    } 
+0

刚添加Layout =“〜/ Views/Shared/_Layout.cshtml”;参考列表包括Bootstrap脚本@ Scripts.Render(“〜/ bundles/jquery”) @ Scripts.Render(“〜/ bundles/bootstrap”) @RenderSection(“scripts”,required:false) –

回答

3

Html.ActionLink的第三个参数表示routeValues。如果你想添加HTML属性(以及一些特定的类),则必须使用其他超载:

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

对于你的情况,你可以通过空对象,或者为null routeValues,这将是:

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

感谢Viktor很爱对你也是! null是代表routeValues的第三个参数,它完全抛弃了我。我现在不会忘记! –

相关问题