Answer the question
In order to leave comments, you need to log in
How to correct parameter passing when calling View Model?
Hello, I have a class FurnitureVM , I use the View Model in my project, and I need to use the model of this class in my view, here is the view:
@model FurnitureStore.ModelView.FurnitureVM
...
<div class="main container-fluid">
@foreach (var p in Model.Furnitures)
{
<div class="product">
@Html.Partial("Summary", p)
</div>
}
</div>
<div class="btn-group pull-right">
@Html.PageLinks(Model.InfoPages, x => Url.Action("List", new { page = x , category = Model.CurrentCategory }))
</div>
public ViewResult List(string category, int page = 1)
{
FurnitureVM model = new FurnitureVM
{
Furnitures = repository.Furnitures
.Where(p => category == null || p.Category.Name== category)
.OrderBy(f => f.FurnitureId)
.Skip((page - 1) * pageSize)
.Take(pageSize),
InfoPages = new InfoPage
{
CurrentPage = page,
ItemsPerPage = pageSize,
TotalItems = category == null ? repository.Furnitures.Count() :
repository.Furnitures.Where(furniture => furniture.Category.Name == category).Count()
},
CurrentCategory = category
};
return View(model);
}
public IEnumerable<Furniture> Furnitures { get; set; }
public IEnumerable<Category> Categories { get; set; }
public InfoPageVM InfoPages { get; set; }
public string CurrentCategory { get; set; }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question