1

I've an indexed page in MVC with data that displays in a table format from the database and using paging. I want to edit only one column of the table. Can I post the paging list to the controller for editing. If so how? I'm able to edit with normal list getting error while passing PagedList

--- this is my index page----

@model PagedList.IPagedList<emp_prac.Models.Employee>
@using PagedList.Mvc;

@*@model List<emp_prac.Models.Employee>*@

@using (Html.BeginForm("UpdateOrder", "Employee", FormMethod.Post))
{
    Html.AntiForgeryToken();
    Html.EditorForModel();
    ViewBag.Title = "Employee Details";

<h2>Employee Details</h2>

<p>
    @Html.ActionLink("Create New", "InsertEmployee")
</p>

<table class="table">
    <thead>
        <tr>
            <th>Edit</th>
            <th>Delete</th>
            <th>Name</th>
            <th>Email</th>
            <th>Phone No</th>
            <th>Salary</th>
            <th>Joining Date</th>
            <th>PDF</th>
            <th>Status</th>
            <th>Order</th>
        </tr>
    </thead>
    <tbody>
@for (int i = 0; i < Model.Count; i++)
{
    <tr>
        <td>@Html.ActionLink("Edit", "EditEmployee", new { id = Model[i].emp_id }) </td>
        <td>@Html.ActionLink("Delete", "DeleteEmployee", new { id = Model[i].emp_id }, new { onclick = "return confirm('Are you sure you want to delete?');", @class = "btn-btn-default" }) </td>
        <td>@Html.DisplayFor(model => model[i].emp_name)</td>
        <td>@Html.DisplayFor(model => model[i].emp_email)</td>
        <td>@Html.DisplayFor(model => model[i].emp_phone_no)</td>
        <td>@Html.DisplayFor(model => model[i].emp_salary)</td>
        <td>@Html.DisplayFor(model => model[i].emp_joining_date)</td>
        <td>@Html.ActionLink("PDF", "UploadPdf", new { id = Model[i].emp_id }) </td>
        <td>@(Html.DisplayFor(model => model[i].emp_status).ToString() == "1" ? "Active" : "Inactive")</td>
        <td>@Html.TextBoxFor(model => model[i].emp_order, new { style = "width: 35px" })</td>
        <td>@Html.HiddenFor(model => model[i].emp_id)</td>
    </tr>
}
        </tbody>
</table>
<button type="submit" value="Order" onclick="location.href='@Url.Action("UpdateOrder","Employee")'">Order</button>
}
    <br />
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
    @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))`

---This is my controller action method---

 [HttpPost]
        public ActionResult UpdateOrder(PagedList<Employee> obj_view)
        {
            foreach (var abc in obj_view)
            {
                Employee obj = new Employee();
                obj.emp_order = abc.emp_order;
                obj.emp_id = abc.emp_id;
                obj.Mode = "O";
                Employee.InsertUpdateEmployee(obj);
            }
            return RedirectToAction("Index");
        }
TLS
  • 3,090
  • 2
  • 25
  • 33
Ashita Shah
  • 139
  • 1
  • 11

1 Answers1

0

I looked deeply into your code , as per my point of view, below line may cause the error.

**<button type="submit" value="Order" onclick="location.href='@Url.Action("UpdateOrder","Employee")'">Order</button>
}**

Reason:

When you post the data through the form post, you no need to specify the onclick in the submit button

Solution:

Just replace the above line with simple submit button like this

**<input type="submit" value="Order" class="btn btn-default" />**

And see in the button click event whether you get the data or not using breakpoint.

Hope you will surely get the data now , kindly let me know your thoughts or feedbacks

Thanks Karthik

Karthik Elumalai
  • 1,574
  • 1
  • 11
  • 12
  • Hmm.Then i think you have problem in some other place also , Ok then try to look at this https://forums.asp.net/t/1995622.aspx?IPagedList+not+posting+back+to+controller , they had similiar kind of problem like yours. I looked at that post ,finally they given the answer and see this works for you too. thanks – Karthik Elumalai May 12 '17 at 07:28