.NetCore Razor HTML Helpers

You can use HTML helpers to get data / data label etc. If you use MVC & EF , it will be easy to manage behaviours from model. You can get data from datacontext using model.

You can use DisplayFor, DisplayNameFor,TextBox,CheckBox,Editor etc. HTML helpers

Take look here : https://www.tutorialsteacher.com/mvc/html-helpers

Here is basic code sample:

@model IEnumerable<ARPredev2SO.Models.SalesOrder>

@{
    ViewData["Title"] = "Index";
}

<h2>Index</h2>

<p>
    <a asp-action="Create">Create New</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Description)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.TotalAmount)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
@foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.TotalAmount)
            </td>
            <td>
                <a asp-action="Edit" asp-route-id="@item.ID">Edit</a> |
                <a asp-action="Details" asp-route-id="@item.ID">Details</a> 
                <a asp-action="Delete" asp-route-id="@item.ID">Delete</a>
            </td>
        </tr>
}
    </tbody>
</table>

Leave a Reply

Your email address will not be published. Required fields are marked *