jeudi 31 décembre 2015

form text area values with pagination

I just referred this article to add pagination for my asp.net mvc 5 project form view page. In this form page it has many text areas(like 15) so I limited one text area per one page.

Now this is working as I expected.

enter image description here

but once I insert date to first text area and then go to next text area , again then I click previous button , then those initially added values for first text area are disappearing ? what wrong with my solution ?

is this because, In my scenario I'm using form ??

this is controller method

    public ActionResult Add_Product(int? page)
    {
        var dummyItems = db.AB_ProductTypeCategoryField;
        var pager = new PaginationModel.Pager(dummyItems.Count(), page);

        var model = new AddNewProduct
        {
            ListProductFields = dummyItems.OrderBy(i => i.ProductFieldID).Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize).ToList(),
            Pager = pager
        };

        return View(model);
    }

this is view page

@model albaraka.Models.AddNewProduct

@{
    ViewBag.Title = "Brochure_Create";
    Layout = "~/Views/Shared/_bootstrapFileUploadLayout.cshtml";
}

<h4>Add New Product</h4>

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()    
    <div class="form-horizontal">      
        @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 

        @for (int i = 0; i < Model.ListProductFields.Count; i++)
        {   

            <div class="form-group">
                @Html.LabelFor(x => x.ListProductFields[i].ProductFieldNameEn, Model.ListProductFields[i].ProductFieldNameEn, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">              
                        @Html.TextAreaFor(m => m.ListProductFields[i].Field_Value_EN, new { @class = "form-control summernote", @row = 5 })
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(x => x.ListProductFields[i].ProductFieldNameAr, Model.ListProductFields[i].ProductFieldNameAr, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                        @Html.TextAreaFor(m => m.ListProductFields[i].Field_Value_AR, new { @class = "form-control summernote", @row = 5 })                 
                </div>
            </div>


                    <!-- pagination section-->
                    @if (Model.Pager.EndPage > 1)
                    {
                        <ul class="pagination">
                        @if (Model.Pager.CurrentPage > 1)
                        {
                                <li>
                                    <a href="~/Home/Add_Product">First</a>
                                </li>
                                <li>
                                    <a href="~/Home/Add_Product?page=@(Model.Pager.CurrentPage - 1)">Previous</a>
                                </li>
                            }

                        @for (var page = Model.Pager.StartPage; page <= Model.Pager.EndPage; page++)
                        {
                                <li class="@(page == Model.Pager.CurrentPage ? "active" : "")">
                                    <a href="~/Home/Add_Product?page=@page">@page</a>
                                </li>
                            }

                        @if (Model.Pager.CurrentPage < Model.Pager.TotalPages)
                        {
                                <li>
                                    <a href="~/Home/Add_Product?page=@(Model.Pager.CurrentPage + 1)">Next</a>
                                </li>
                                <li>

                                    <a href="~/Home/Add_Product?page=@(Model.Pager.TotalPages)">Last</a>
                                </li>
                            }
                        </ul>
                    }


        }



        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>


    </div>

}

this is relevant model classes

public class AddNewProduct
{
        public IList<AB_ProductTypeCategoryField> ListProductFields { get; set; }    
        public Pager Pager { get; set; }
}
public partial class AB_ProductTypeCategoryField
{
    public string ProductFieldNameEn { get; set; }
    public string ProductFieldNameAr { get; set; }

    public string Field_Value_EN { get; set; }
    public string Field_Value_AR { get; set; }
}

Aucun commentaire:

Enregistrer un commentaire