1

Hi could someone cast a quick eye over the attached to see why the button is not picking up the bootstrap class correctly.

The Actionlink item in question is at the very end of the view.

I have tried moving the @section scripts section to different parts of the page but it has made no difference.

Thanks John

@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")
    }
1
  • Just to add the Layout = "~/Views/Shared/_Layout.cshtml"; reference listed includes the Bootstrap script @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required: false) Commented Aug 28, 2015 at 19:27

1 Answer 1

3

The third parameter of Html.ActionLink represents the routeValues. If you want to add html attributes (and some specific class) you must use another overload:

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

For your case you can pass empty object or null for routeValues and it would be:

@Html.ActionLink("Add a new journey", "Create", null, new { @class = "btn btn-default"})
Sign up to request clarification or add additional context in comments.

1 Comment

thanks Viktor much love to you too! That null being the third parameter representing the routeValues was throwing me completely. I won't forget that now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.