glitch when using with ASP.NET MVC

glitch when using with ASP.NET MVC

johnny024johnny024 Posts: 2Questions: 0Answers: 0
edited November 2013 in General
Hello,
I have implemented dataTables into my ASP.NET MVC project where I render a table using EditorFor() display templates. Therefore, what is happening is I have a model, which has a list of model objects loading as rows into the table (accounts model loads a list of person models as display templates to the table). The problem I am having is that dataTables deletes the models when using the next, previous and the search features. It is really strange, because the rows are still there, but when posting to the controller, the list of models attribute is null. However, If I load the first 30 models on page, and dont use one of these features, the post will contain the first 30 models. Is there any way to keep all the models? Otherwise this wont be able to hold much functionality for MVC besides displaying for items.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you are using paging in DataTables (or filtering) it will remove from the document rows which it doesn't want to display. Those rows are then reinserted when needed, if they are needed.

    Can you link use to the page please so I can take a look at the issue and hopefully suggest a fix.

    Allan
  • johnny024johnny024 Posts: 2Questions: 0Answers: 0
    edited November 2013
    [code]
    @model project.Models.OrdersModel
    Account






    $(document).ready(function () {
    $("#orders").dataTable();
    });


    .section
    {
    padding-bottom:10px;
    padding-top:10px;
    }
    #loadingGif
    {
    border:solid;
    border-color:Black;
    border-radius: 15px;
    border-width:2px;
    border-style:outset;
    width:60px;
    height:60px;
    background-color:White;
    -webkit-box-shadow:5px 2px 2px #bbb;
    }



    List of People:
    @using (Html.BeginForm("SearchPeople", "People", FormMethod.Post))
    {
    <!--
    List of People
    -->




    CheckBox


    Name



    @Html.EditorFor(x => x.People)

    }

    [/code]

    As you see, this is an Account Model, which holds a list of List (Person Models). The EditorFor() will insert this partial view below for each person model in the list.

    [code]
    @model Project.Models.PersonModel


    @Html.CheckBoxFor(m => m.IsChecked)


    @Model.Name


    [/code]

    So, what im trying to say, is that the list of person models above, the partial view from a list, doesn't work with dataTables. Try it yourself. try to update any item while using the next, previous, or search feature and it will post the null value in the List field.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Sorry, I don't have an ASP.NET server set up to try it.

    Allan
This discussion has been closed.