Sagar Bandkar

Sagar Bandkar

  • 1.3k
  • 347
  • 47.4k

2 View not call from first one in mvc using ViewModel

Dec 10 2016 6:25 AM
ViewModel:-
public class ProductPageViewModel
{
public string Message { get; set; }
public List<ProductViewModel> ProductsList { get; set; }
}
public class ProductViewModel
{
public bool Selected{ get; set; }
public int inCosId { get; set; }
public string vcCosCode { get; set; }
public string vcCosName { get; set; }
public string vcCosDesc { get; set; }
}
 
View 1:
@model EditorForSample.Models.ProductPageViewModel
@{
ViewBag.Title = "Select Products Page";
}
<table class="table table-bordered table-striped" id="example">
<thead>
<tr>
<th style="width:50px"><input type="checkbox" id="chkSelectAll"/></th>
<th><input type="text" class="search" hidden>Code</th>
</tr>
</thead>
<tbody>
@Html.EditorFor(m => m.ProductsList)
</tbody>
</table>
 
View 2:-
@model EditorForSample.Models.ProductViewModel
<tr>
<td class="text-nowrap">@Html.CheckBoxFor(m => m.Selected, new { @class = "chkSelect" })</td>
<td colspan="3">
@Model.vcCosCode
@Html.HiddenFor(m => m.inCosId)
</td>
</tr>
 
Controller
public ActionResult Index()
{
ProductPageViewModel model = new ProductPageViewModel();
var data = from cos in db.tblMstCostCenter_COS select cos;
model.ProductsList = new List<ProductViewModel>();
ProductViewModel product = null;
foreach (var u in data)
{
product = new ProductViewModel();
product.inCosId = u.inCosId;
product.vcCosName = u.vcCosName;
product.vcCosCode = u.vcCosCode;
product.Selected = false;
model.ProductsList.Add(product);
}
//string JSONresult;
//JSONresult = JsonConvert.SerializeObject(model.ProductsList);
//Response.Write(JSONresult);
return View(model);
}
 
 

Answers (4)