mardi 29 décembre 2015

load one item per page [ Pagination ]

I have a viewpage like below

enter image description here

this is the controller method for above view

public ActionResult Add_Product()
{       
    var model = new AddNewProduct
    {
        ListProductFields = db.AB_ProductTypeCategoryField.ToList()
    };

    return View(model);
}

this is model class for above view

public class AddNewProduct
{
    public string Product_ID { get; set; }
    public string ProductTypeID { get; set; }
    public string ProductCategoryID { get; set; }
    public string Subsidary_ID { get; set; }

    public IList<AB_ProductTypeCategoryField> ListProductFields { get; set; }
}
public partial class AB_ProductTypeCategoryField
{
    public string Field_Value_EN { get; set; }
    public string Field_Value_AR { get; set; }
}

this is viewpage

@model albaraka.Models.AddNewProduct

@using (Html.BeginForm()) 
{        

        @for (int i = 0; i < Model.ListProductFields.Count; i++)
        { 
          @Html.TextAreaFor(m => m.ListProductFields[i].Field_Value_EN, new { @class = "form-control summernote", @row = 5 })

          @Html.TextAreaFor(m => m.ListProductFields[i].Field_Value_AR, new { @class = "form-control summernote", @row = 5 })
        }

}

Now I want to add pagination for above view page and limit one ListProductFields per one page , for that I following this Tutorial

So I change my code to like this

    public ActionResult Add_Product(int? page)
    {

        var dummyItems = db.AB_ProductTypeCategoryField.Select(x => "Item " + x);
        var pager = new PaginationModel.Pager(dummyItems.Count(), page);


        var model = new AddNewProduct
        {
            Items = dummyItems.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize).ToList(),
            Pager = pager
        };

        return View(model);

    }

But then I'm getting following Run-time Error

Values of type 'AB_ProductTypeCategoryField' can not be converted to string.

Aucun commentaire:

Enregistrer un commentaire