0
I have a supplier object, and each supplier has several contacts, on the page, has a tab for the supplier registration, and another tab for the registration of contacts, the contact registration tab has a small form, and below a table where to each item registered in the form, I insert into the table using Javascript. After this page has a tab filled with vendor data and in the other tab an HTML table with a contact list, I need to send this to controller to register in the database.
In my View I use a Viewmodel Like this:
public class FornecedorContatoViewModel
{
public Fornecedor Fornecedor { get; set; }
public Contato Contato { get; set; }
}
The form is made with Razor, and the table is HTML even.
In the controller, something like:
public ActionResult Add(Fornecedor fornecedor, IList<Contato> contato)
{
}
And how to make the whole table go to the action in the form of a list (List in this case), as would be the Submit, could do normally?
Yes, and the controller code is absolutely correct.
– Jéf Bueno
@jbueno, you’re right, or you’re being sarcastic?
– Alan Almeida
That’s right, young man. I don’t use the site to be sarcastic. Of course there are other ways to do it, some even more indicated depending on the context of the project. But this way it will work perfectly.
– Jéf Bueno
Thank you very much, you see, it’s just that I’ve been sarcastic with myself here, and I figured that wouldn’t work. If you have any link to any article about the most indicated ways to do this as you mentioned, post as an answer that then I already mark your answer. Thank you.
– Alan Almeida
The intention is not to have this kind of behavior here. Whenever it happens you can flag the comment (or the post). The site has a team of moderators that can take care of it. About answer: responses only with links are not well seen (or useful for the site). I could create an answer for you, but first I need to understand what the problem itself is. You just want an example of how you can send two parameters to controller? If you can make the question clearer, it would be nice [Dit]. [+]
– Jéf Bueno
[+] This way the question can be useful for anyone who has the same + doubt in the future and you will get your answer. In addition, other users may publish new responses showing other ways to do so, etc.
– Jéf Bueno
OK I’ll edit the question and try to make it clear.
– Alan Almeida
So. It looks better with your editing. Now my idea is different. You don’t need two parameters in the action
Add
. You only need oneFornecedorContatoViewModel
. It still works at first, but I see no point in following two different patterns. If you’re using withViewModel
follow this path and be happy.– Jéf Bueno
Really, now that you’ve spoken it makes more sense anyway. Thank you for your help
– Alan Almeida
I was thinking here now, using Viewmodel, how it has a property Contact and not a List<Contact>, would it receive several contacts inserted in the table?
– Alan Almeida
So. I was writing about it. Take a look at the answer.
– Jéf Bueno