Model with dynamic list property lost values on postback
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
add a comment |
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
add a comment |
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
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
.net model-view-controller
asked Nov 9 at 22:42
Dave
12
12
add a comment |
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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