Model with dynamic list property lost values on postback
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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