3
I’m having trouble forwarding my model to control:
Class:
public class Pessoa { public virtual long Id {get; set;} public virtual string Nome {get; set;} public virtual ETipo Tipo {get; set;} public virtual List ListaClientes {get; set;} }
View:
@using Projeto.Model.Enum @model projeto.Model.Cadastro.Pessoa @{ title = ".." List lstCliente = Model.ListaClientes; } @using (Ajax.BeginForm("SalvaPessoa", "Home", new AjaxOptions { HttpMethod = "POST"})) { @Html.Hidden(m => m.Id) @Html.Hidden(m => m.Nome) @Html.Hidden(m => m.Tipo) @foreach(var x in @lstCliente){ Cliente @Html.CheckboxFor(m => m.ListaClientes.IsAtivo, new{ class = "form"}) } Salvar }
Controller:
public JsonResult SalvaPessoa(Pessoa model){ ... }
So, all the fields are coming right into mine Salvapessoa() method, except for my list changed the Isativo bool inside the form;
All fields are valued, even the list already comes from my Actionresult() Valued.
Can anyone help me on how to make this my list be sent with Salvapessoa()?
The way you are doing, the form will send a bool array to the controller.
– Marcell Alves
Like I’d have to do in this case?
– Eluander J. F. Lopes
This link helped me make an implementation that sends a model with a list to the controller. https://www.codeproject.com/Tips/855577/List-of-Model-Object-Post-to-Controller-in-ASP-NET
– Thiago Santiago