locked
Property as Link to Details View RRS feed

  • Question

  • User2074931137 posted

    Question Illustrated (PDF)

    Question: How do I code the properties under the Menu column to be links to Details (ultimately allowing the elimination of the Details link altogether)?  I.E. When you click on the Menu properties it goes to Details.

     

    @model IEnumerable<fvm.Areas.Office.Models.DocumentMenu>
    
    @{
        ViewBag.Title = "Index";
    }
    
    @*<h2>Index</h2>*@
    
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table class="table">
        <tr>
            <th>
                Menu
            </th>
            <th>
                Details
            </th>
        </tr>
    
    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.DocumentMenuCategoryDisplay)
            </td>
            <td>
                @Html.ActionLink("Details", "Details", new { id = item.DocumentMenuID })
            </td>
        </tr>
    }
    
    </table>
    

    Monday, June 24, 2019 11:56 AM

Answers

  • User1520731567 posted

    Hi 3v3rhart,

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.DocumentMenuCategoryDisplay)
            </td>
            <td>
                @Html.ActionLink("Details", "Details", new { id = item.DocumentMenuID })
            </td>
        </tr>
    }
    

    Also,you could make Html.DisplayFor and Html.ActionLink together,like:

    @foreach (var item in Model) {
        <tr>
            @Html.ActionLink(@item.DocumentMenuCategoryDisplay, "Details", new { id = item.DocumentMenuID})
    
        </tr>
    }

    it will generate html:

    <a href="/ControllerName/Details/1">your properties</a>

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2019 2:52 AM

All replies

  • User2074931137 posted

    .

    Monday, June 24, 2019 12:22 PM
  • User-474980206 posted

    just use an anchor:

    <td>
       <a href="@Html.ActionLink("Details", "Details", new { id = item.DocumentMenuID })"> 
           @Html.DisplayFor(modelItem => item.DocumentMenuCategoryDisplay)
       </a>            
    </td>

    Monday, June 24, 2019 2:01 PM
  • User1520731567 posted

    Hi 3v3rhart,

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.DocumentMenuCategoryDisplay)
            </td>
            <td>
                @Html.ActionLink("Details", "Details", new { id = item.DocumentMenuID })
            </td>
        </tr>
    }
    

    Also,you could make Html.DisplayFor and Html.ActionLink together,like:

    @foreach (var item in Model) {
        <tr>
            @Html.ActionLink(@item.DocumentMenuCategoryDisplay, "Details", new { id = item.DocumentMenuID})
    
        </tr>
    }

    it will generate html:

    <a href="/ControllerName/Details/1">your properties</a>

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2019 2:52 AM