CRUD APPLICATION IN ASP.NET MVC (PROJECT MODEL) [PART 2]

 CONTROLLER CODE:            


 public ActionResult Index()

   {

        List<tbl_employee> emplist = db.tbl_employee.ToList();


List<employeeviewmode> evmlist = emplist.Select(x => new employeeviewmode

            {

                emp_id = x.emp_id,

                emp_name = x.emp_name,

                emp_email = x.emp_email,

                emp_contact = x.emp_contact,

                dep_name = x.tbl_depart.dep_name

            }).ToList();

            return View(evmlist);


        }


VIEW CODE:

@model IEnumerable<crdu.Models.employeeviewmode>


@{

    ViewBag.Title = "Home Page";

}

<a class="btn btn-primary" href="@Url.Action("Create")">ADD NEW RECORD</a>

<table class="table table-bordered table-condensed">


    <thead>

        <tr>

            <td>Emp ID</td>

            <td>Emp Name</td>

            <td>Emp Email</td>

            <td>Emp Contact</td>


            <td>Depart Name</td>


        </tr>

    </thead>


    <tbody>

        @if (Model!=null)

        {


            foreach (var item in Model)

            {

                <tr>

                    <td>@item.emp_id</td>

                    <td>@item.emp_name</td>

                    <td>@item.emp_email</td>

                    <td>@item.emp_contact</td>

                    <td>@item.dep_name</td>



                </tr>

            }

        }


    </tbody>


</table>

Comments