Hi
Compiler Error Message: CS1061: 'MyViewModel' does not contain a definition for 'Id' and no extension method 'Id' accepting a first argument of type 'MyViewModel' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 23: <tr> Line 24: <th> Line 25: @Html.DisplayNameFor(model => model.Id) Line 26: </th> Line 27: <th>
public ActionResult Index() { //MyViewModel lvm = new MyViewModel(); //lvm.Customers = dbCustomer.GetAllCustomer().ToList(); //lvm.Customer = new Customer(); //return View(lvm); return View(); } public JsonResult List() { MyViewModel lvm = new MyViewModel(); lvm.Customers = dbCustomer.GetAllCustomer().ToList(); lvm.Customer = new Customer(); return Json(lvm, JsonRequestBehavior.AllowGet); //return Json(dbCustomer.GetAllCustomer().ToList(), JsonRequestBehavior.AllowGet); }
@model MyApplication.Models.ViewModel.MyViewModel
<html> <head> </head> <body> <div class="table-title"> <div class="row"> <div class="col-sm-6"> <h2>Manage <b>Customers</b></h2> </div> <div class="col-sm-6 text-right"> <button type="button" id="btnAdd" class="btn btn-primary" float-right onclick="clearTextBox();"> <i class="fa fa-plus"></i> Add New Customer</button><br /><br /> </div> </div> </div> <div class="row"> <div class="col-xs-12"> <div class="box"> <div class="box-body"> <table class="table table-striped table-bordered" style="width:100%" id="tblCustomer"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.Id) </th> <th> @Html.DisplayNameFor(model => model.Description) </th> <th> @Html.DisplayNameFor(model => model.IsActive) </th> <th>Action</th> </tr> </thead> <tbody class="tbody"></tbody> </table> </div> </div> </div> </div>
</body> </html>