In this case, you need to create a Viewmodel. A Viewmodel is identical to a Model, but does not store information in a bank.
Put into it all the properties of the various Models that will be saved. By sending to Controller, you will have to create the Models manually and enter the information ViewModel
.
[HttpPost]
public ActionResult MinhaAction(MeuViewModel viewModel)
{
if (ModelState.IsValid)
{
var model1 = new MeuModel1();
model1.Prop1 = viewModel.Prop1;
model1.Prop2 = viewModel.Prop2;
...
context.MeuModel1.Add(model1);
context.SaveChanges();
var model2 = new MeuModel2();
model2.Prop1 = viewModel.Prop3;
model2.Prop2 = viewModel.Prop4;
...
context.MeuModel2.Add(model2);
context.SaveChanges();
return RedirectToAction("OutraAction");
}
// Caso o ViewModel não seja válido, cai aqui.
return View(viewModel);
}
Where are these other values you need to take?
– Leonel Sanches da Silva
I want to do the following. Create a form that will insert information in more than one table in the event click save button. But when like View I can only use the properties of that entity that it was typed. I hope I was clear.
– Rabelos