-1
When I set mine action register address, she picks up the codigoCliente
,
parameter master/CadastrarEndereco?codigoCliente=1011
.
How to persist the chosen customer’s address?
My actions:
public ActionResult CadastrarEndereco(int codigoCliente)
{
var endereco = new Endereco();
endereco.CodigoCliente = codigoCliente;
return View();
}
[HttpPost]
public ActionResult CadastrarEndereco(EnderecoViewModel enderecoVM)
{
if (ModelState.IsValid)
{
var endereco = Extentions.MapearEndereco(enderecoVM);
endereco.CodigoCliente = codigoCliente;
EnderecoRepositorio.Cadastrar(endereco);
EnderecoRepositorio.Commit();
}
return View(enderecoVM);
}
Why don’t you return an Addressmodel type instead of Addressmodel to your view? Then leave the Customer’s code in an Hidden input, when you see in the Post, you will have the Customer’s code
– Rod
How does your business work? Do you have a customer registration and each customer has an address (which is more common to happen)? Or do you have an Address Register? Is your question about taking the parameter or how to persist in the bank? Anyway, give us more information about the functionality you are developing to try to help.
– Renan
beauty! I have a customer register where I register and populate a grid ,,on my grid I have customer data and an address field,in the address field I have a link register address, next to each customer inserted,the link directs to a address registration view,passing through parameters the Codigodocliente in which, I want to insert an address. Problem is: I cannot persist my data in the database ,just because my view is not getting this value from the Code to enter into the database
– Hans Miller
You can put in your question the statement of Viewmodel used in the Controller?
– Leonel Sanches da Silva