Model with dynamic list property lost values on postback










0














My model have a property list and this property has another inside.
I made changes to this properties list before make submit but many properties hasn't values, they lost.



Main Model with lists



public class PedidosViewModel : BaseFormViewModel<long>

//Main properties here

public List<PedidosDetalleViewModel> PedidosDetalle get; set;


public class PedidosDetalleViewModel

public long Id get; set;
public long IdPedido get; set;
public long IdEstiloCombinacion get; set;
public string Combinacion get; set;
public string Descripcion get; set;
[Required]
[RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
public int CantidadPares get; set; = 0;
public decimal Precio get; set;
public decimal PrecioMoneda get; set;
public decimal Importe get; set;
public decimal ImporteMoneda get; set;
public int Estatus get; set;
public string EstatusStr get; set;
public List<PedidosDetalleCorridaViewModel> PedidosDetalleCorrida get; set;


public class PedidosDetalleCorridaViewModel

public long Id get; set;
public long IdPedidoDetalle get; set;
[StringLength(20)]
public string Punto get; set;
[StringLength(20)]
public string Valor get; set;
[RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
public int CantidadPares get; set; = 0;



In the partial view with the list details i have:



@ int rowNum = 0; 
@for (int j = 0; j < Model.PedidosDetalle.Count(); j++)

<tr>
<td>
@(rowNum += 1)
@Html.HiddenFor(m => m.PedidosDetalle[j].Id)
@Html.HiddenFor(m => m.PedidosDetalle[j].IdEstiloCombinacion)
@Html.HiddenFor(m => m.PedidosDetalle[j].IdPedido)
@Html.HiddenFor(m => m.PedidosDetalle[j].Combinacion)
@Html.HiddenFor(m => m.PedidosDetalle[j].Descripcion)
@Html.HiddenFor(m => m.PedidosDetalle[j].Precio)
@Html.HiddenFor(m => m.PedidosDetalle[j].PrecioMoneda)
@Html.HiddenFor(m => m.PedidosDetalle[j].Importe)
@Html.HiddenFor(m => m.PedidosDetalle[j].ImporteMoneda)
@Html.HiddenFor(m => m.PedidosDetalle[j].Estatus)
@Html.HiddenFor(m => m.PedidosDetalle[j].EstatusStr)
@Html.HiddenFor(m => m.PedidosDetalle[j].CantidadPares)
@for (int i = 0; i < Model.PedidosDetalle[j].PedidosDetalleCorrida.Count(); i++)

@Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Id)
@Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].IdPedidoDetalle)
@Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Punto)
@Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Valor)
@Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].CantidadPares)

</td>
<td>@Html.DisplayFor(m => m.PedidosDetalle[j].Combinacion)</td>
<td>@Html.DisplayFor(m => m.PedidosDetalle[j].Descripcion)</td>
<td>@Html.DisplayFor(m => m.PedidosDetalle[j].CantidadPares)</td>
<td>@Html.DisplayFor(m => m.PedidosDetalle[j].PrecioMoneda)</td>
<td>@Html.DisplayFor(m => m.PedidosDetalle[j].ImporteMoneda)</td>
<td>@Html.DisplayFor(m => m.PedidosDetalle[j].EstatusStr)</td>
<td>
<a class="btn btn-md btn-primary" onclick="CargarDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="fa fa-pencil"></i> Editar</a>
</td>
<td>
<a onclick="EliminarPedidoDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="glyphicon glyphicon-remove-sign icons-app icons-md icons-app-danger"></i></a>
</td>
</tr>



as you can see many hidden controls just for keep the values when i postback, but properties like Id, Importe, Estatus lost their values. I am thinking to use session (because .net MVC don't have viewstates) for save temporary my detail list with all values and edit values list if i need just before save changes.
I use javascript for load the partial view with an ajax call for pass all the form serialized every time i add new record in the list.
There is a solution with MVC, Ajax and mainting the values in my main model.



This is the screen:
enter image description here










share|improve this question


























    0














    My model have a property list and this property has another inside.
    I made changes to this properties list before make submit but many properties hasn't values, they lost.



    Main Model with lists



    public class PedidosViewModel : BaseFormViewModel<long>

    //Main properties here

    public List<PedidosDetalleViewModel> PedidosDetalle get; set;


    public class PedidosDetalleViewModel

    public long Id get; set;
    public long IdPedido get; set;
    public long IdEstiloCombinacion get; set;
    public string Combinacion get; set;
    public string Descripcion get; set;
    [Required]
    [RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
    public int CantidadPares get; set; = 0;
    public decimal Precio get; set;
    public decimal PrecioMoneda get; set;
    public decimal Importe get; set;
    public decimal ImporteMoneda get; set;
    public int Estatus get; set;
    public string EstatusStr get; set;
    public List<PedidosDetalleCorridaViewModel> PedidosDetalleCorrida get; set;


    public class PedidosDetalleCorridaViewModel

    public long Id get; set;
    public long IdPedidoDetalle get; set;
    [StringLength(20)]
    public string Punto get; set;
    [StringLength(20)]
    public string Valor get; set;
    [RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
    public int CantidadPares get; set; = 0;



    In the partial view with the list details i have:



    @ int rowNum = 0; 
    @for (int j = 0; j < Model.PedidosDetalle.Count(); j++)

    <tr>
    <td>
    @(rowNum += 1)
    @Html.HiddenFor(m => m.PedidosDetalle[j].Id)
    @Html.HiddenFor(m => m.PedidosDetalle[j].IdEstiloCombinacion)
    @Html.HiddenFor(m => m.PedidosDetalle[j].IdPedido)
    @Html.HiddenFor(m => m.PedidosDetalle[j].Combinacion)
    @Html.HiddenFor(m => m.PedidosDetalle[j].Descripcion)
    @Html.HiddenFor(m => m.PedidosDetalle[j].Precio)
    @Html.HiddenFor(m => m.PedidosDetalle[j].PrecioMoneda)
    @Html.HiddenFor(m => m.PedidosDetalle[j].Importe)
    @Html.HiddenFor(m => m.PedidosDetalle[j].ImporteMoneda)
    @Html.HiddenFor(m => m.PedidosDetalle[j].Estatus)
    @Html.HiddenFor(m => m.PedidosDetalle[j].EstatusStr)
    @Html.HiddenFor(m => m.PedidosDetalle[j].CantidadPares)
    @for (int i = 0; i < Model.PedidosDetalle[j].PedidosDetalleCorrida.Count(); i++)

    @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Id)
    @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].IdPedidoDetalle)
    @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Punto)
    @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Valor)
    @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].CantidadPares)

    </td>
    <td>@Html.DisplayFor(m => m.PedidosDetalle[j].Combinacion)</td>
    <td>@Html.DisplayFor(m => m.PedidosDetalle[j].Descripcion)</td>
    <td>@Html.DisplayFor(m => m.PedidosDetalle[j].CantidadPares)</td>
    <td>@Html.DisplayFor(m => m.PedidosDetalle[j].PrecioMoneda)</td>
    <td>@Html.DisplayFor(m => m.PedidosDetalle[j].ImporteMoneda)</td>
    <td>@Html.DisplayFor(m => m.PedidosDetalle[j].EstatusStr)</td>
    <td>
    <a class="btn btn-md btn-primary" onclick="CargarDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="fa fa-pencil"></i> Editar</a>
    </td>
    <td>
    <a onclick="EliminarPedidoDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="glyphicon glyphicon-remove-sign icons-app icons-md icons-app-danger"></i></a>
    </td>
    </tr>



    as you can see many hidden controls just for keep the values when i postback, but properties like Id, Importe, Estatus lost their values. I am thinking to use session (because .net MVC don't have viewstates) for save temporary my detail list with all values and edit values list if i need just before save changes.
    I use javascript for load the partial view with an ajax call for pass all the form serialized every time i add new record in the list.
    There is a solution with MVC, Ajax and mainting the values in my main model.



    This is the screen:
    enter image description here










    share|improve this question
























      0












      0








      0







      My model have a property list and this property has another inside.
      I made changes to this properties list before make submit but many properties hasn't values, they lost.



      Main Model with lists



      public class PedidosViewModel : BaseFormViewModel<long>

      //Main properties here

      public List<PedidosDetalleViewModel> PedidosDetalle get; set;


      public class PedidosDetalleViewModel

      public long Id get; set;
      public long IdPedido get; set;
      public long IdEstiloCombinacion get; set;
      public string Combinacion get; set;
      public string Descripcion get; set;
      [Required]
      [RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
      public int CantidadPares get; set; = 0;
      public decimal Precio get; set;
      public decimal PrecioMoneda get; set;
      public decimal Importe get; set;
      public decimal ImporteMoneda get; set;
      public int Estatus get; set;
      public string EstatusStr get; set;
      public List<PedidosDetalleCorridaViewModel> PedidosDetalleCorrida get; set;


      public class PedidosDetalleCorridaViewModel

      public long Id get; set;
      public long IdPedidoDetalle get; set;
      [StringLength(20)]
      public string Punto get; set;
      [StringLength(20)]
      public string Valor get; set;
      [RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
      public int CantidadPares get; set; = 0;



      In the partial view with the list details i have:



      @ int rowNum = 0; 
      @for (int j = 0; j < Model.PedidosDetalle.Count(); j++)

      <tr>
      <td>
      @(rowNum += 1)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Id)
      @Html.HiddenFor(m => m.PedidosDetalle[j].IdEstiloCombinacion)
      @Html.HiddenFor(m => m.PedidosDetalle[j].IdPedido)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Combinacion)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Descripcion)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Precio)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PrecioMoneda)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Importe)
      @Html.HiddenFor(m => m.PedidosDetalle[j].ImporteMoneda)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Estatus)
      @Html.HiddenFor(m => m.PedidosDetalle[j].EstatusStr)
      @Html.HiddenFor(m => m.PedidosDetalle[j].CantidadPares)
      @for (int i = 0; i < Model.PedidosDetalle[j].PedidosDetalleCorrida.Count(); i++)

      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Id)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].IdPedidoDetalle)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Punto)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Valor)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].CantidadPares)

      </td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].Combinacion)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].Descripcion)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].CantidadPares)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].PrecioMoneda)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].ImporteMoneda)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].EstatusStr)</td>
      <td>
      <a class="btn btn-md btn-primary" onclick="CargarDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="fa fa-pencil"></i> Editar</a>
      </td>
      <td>
      <a onclick="EliminarPedidoDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="glyphicon glyphicon-remove-sign icons-app icons-md icons-app-danger"></i></a>
      </td>
      </tr>



      as you can see many hidden controls just for keep the values when i postback, but properties like Id, Importe, Estatus lost their values. I am thinking to use session (because .net MVC don't have viewstates) for save temporary my detail list with all values and edit values list if i need just before save changes.
      I use javascript for load the partial view with an ajax call for pass all the form serialized every time i add new record in the list.
      There is a solution with MVC, Ajax and mainting the values in my main model.



      This is the screen:
      enter image description here










      share|improve this question













      My model have a property list and this property has another inside.
      I made changes to this properties list before make submit but many properties hasn't values, they lost.



      Main Model with lists



      public class PedidosViewModel : BaseFormViewModel<long>

      //Main properties here

      public List<PedidosDetalleViewModel> PedidosDetalle get; set;


      public class PedidosDetalleViewModel

      public long Id get; set;
      public long IdPedido get; set;
      public long IdEstiloCombinacion get; set;
      public string Combinacion get; set;
      public string Descripcion get; set;
      [Required]
      [RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
      public int CantidadPares get; set; = 0;
      public decimal Precio get; set;
      public decimal PrecioMoneda get; set;
      public decimal Importe get; set;
      public decimal ImporteMoneda get; set;
      public int Estatus get; set;
      public string EstatusStr get; set;
      public List<PedidosDetalleCorridaViewModel> PedidosDetalleCorrida get; set;


      public class PedidosDetalleCorridaViewModel

      public long Id get; set;
      public long IdPedidoDetalle get; set;
      [StringLength(20)]
      public string Punto get; set;
      [StringLength(20)]
      public string Valor get; set;
      [RegularExpression(@"^[0-9]*$", ErrorMessage = "La Cantidad debe ser numérico entero")]
      public int CantidadPares get; set; = 0;



      In the partial view with the list details i have:



      @ int rowNum = 0; 
      @for (int j = 0; j < Model.PedidosDetalle.Count(); j++)

      <tr>
      <td>
      @(rowNum += 1)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Id)
      @Html.HiddenFor(m => m.PedidosDetalle[j].IdEstiloCombinacion)
      @Html.HiddenFor(m => m.PedidosDetalle[j].IdPedido)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Combinacion)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Descripcion)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Precio)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PrecioMoneda)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Importe)
      @Html.HiddenFor(m => m.PedidosDetalle[j].ImporteMoneda)
      @Html.HiddenFor(m => m.PedidosDetalle[j].Estatus)
      @Html.HiddenFor(m => m.PedidosDetalle[j].EstatusStr)
      @Html.HiddenFor(m => m.PedidosDetalle[j].CantidadPares)
      @for (int i = 0; i < Model.PedidosDetalle[j].PedidosDetalleCorrida.Count(); i++)

      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Id)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].IdPedidoDetalle)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Punto)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].Valor)
      @Html.HiddenFor(m => m.PedidosDetalle[j].PedidosDetalleCorrida[i].CantidadPares)

      </td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].Combinacion)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].Descripcion)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].CantidadPares)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].PrecioMoneda)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].ImporteMoneda)</td>
      <td>@Html.DisplayFor(m => m.PedidosDetalle[j].EstatusStr)</td>
      <td>
      <a class="btn btn-md btn-primary" onclick="CargarDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="fa fa-pencil"></i> Editar</a>
      </td>
      <td>
      <a onclick="EliminarPedidoDetalle(@Model.PedidosDetalle[j].Id)" href="javascript:void(0);"><i class="glyphicon glyphicon-remove-sign icons-app icons-md icons-app-danger"></i></a>
      </td>
      </tr>



      as you can see many hidden controls just for keep the values when i postback, but properties like Id, Importe, Estatus lost their values. I am thinking to use session (because .net MVC don't have viewstates) for save temporary my detail list with all values and edit values list if i need just before save changes.
      I use javascript for load the partial view with an ajax call for pass all the form serialized every time i add new record in the list.
      There is a solution with MVC, Ajax and mainting the values in my main model.



      This is the screen:
      enter image description here







      .net model-view-controller






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 22:42









      Dave

      12




      12



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234193%2fmodel-with-dynamic-list-property-lost-values-on-postback%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234193%2fmodel-with-dynamic-list-property-lost-values-on-postback%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Edmonton

          Crossroads (UK TV series)