1
I have two Customer and Address entity where the customer has multiple addresses. At the time of completing the form, the user can add two addresses in the same form and at the time of Submit, I would like to receive customer data and more than one address completed in the same form. How can I receive in my Controller the Client filled with more than one Submit address ?
In My MVC project I am following the DDD architecture strategy where my Application layer contains my Viewsmodel with the Clienteaddressmodel, Clienteviewmodel and Addressmodel classes where you chat with my Presentation Clientecontroller layer.
My Clienteaddresseewmodel has the following prop below
public Guid ClienteId { get; set; }
public string Nome { get; set; }
public string Email { get; set; }
public string CPF { get; set; }
public ICollection<EnderecoViewModel> ListEnderecoViewModels { get; set; }
My Clientecontroller
public ActionResult Create( ClienteEnderecoViewModel clienteEnderecoViewModel)
{
if (ModelState.IsValid)
{
_clienteAppService.Adicionar(clienteEnderecoViewModel);
return RedirectToAction("Index");
}
return View(clienteEnderecoViewModel);
}
My Create.CSHTML
<h4>Endereco </h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Logradouro, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ListEnderecoViewModels, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Logradouro, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Numero, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Numero, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Numero, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Complemento, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Complemento, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Complemento, "", new { @class = "text-danger" })
</div>
</div>
thanks for the reply. The solution was met after the implementation.
– Bruno Leite
I didn’t understand it right. My answer solved your problem?
– user26552
Yes @Murílo ! Thank you.
– Bruno Leite