Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • @Html.DisplayFor in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    In MVC while creating views we need to show data in the page which contain the different kind of HTML controls.

     

     

    For this we have one control called the @Html.DisplayFor that is like a label we have in HTML.

     

     

    So it is mainly used to only display data in the view.

     

     

    We will first create action for the employee model.

     

     public ActionResult Index()
            {
                EmpRep = new EmployeeRepository();
                List<EmployeeModel> EmpMod = new List<EmployeeModel>();
                EmpMod = EmpRep.GetDetails().ToList();
                return View(EmpMod);
            }

     

     

    After doing that we will create the view that will show the data for the entity values that we get from the database.

     

     

    @model IEnumerable<Modal_PopUp_Basic.Models.EmployeeModel>
    
    @{
        ViewBag.Title = "Index";
    }
    
    
    
    <h2>Index</h2>
    
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.EmpId)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.FirstName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.MiddleName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LastName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PhoneNo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Address)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.msg)
            </th>
            <th></th>
        </tr>
    
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.EmpId)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.FirstName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MiddleName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PhoneNo)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Address)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.msg)
                </td>
                <td>
                    <a class="lnkEdit" id='@item.EmpId'>Edit</a> | |
                    @Html.ActionLink("Details", "Details", new { id = item.EmpId }, new { @class = "lnkDetail" }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.EmpId }, new { @class = "lnkDelete" })
                </td>
            </tr>
        }
    
    </table>
    
    
    
    
    
    
    
    
    

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: