M
M
MADm2016-07-20 12:41:38
ASP.NET
MADm, 2016-07-20 12:41:38

How to build a PartialView in such a way that model binding works?

There are several entities with CRUD functionality. Let's say there is a company and there is a contact. Relationship 1 to many. One company can have many contacts. There is a separate creation of a company, there is a separate creation of a contact. There is a requirement to create both a contact and a company on the same form at the same time. I would like to do this through PartialView in case we change the company model or the contact has changed in two places at once. There are 2 ViewModels for each entity. The problem is that the name for the input is generated based on the partialView. And the same fields interrupt each other. How can such a problem be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MADm, 2016-07-20
@MADm

Anyway, it turned out to google the solution, all you had to know was the parameters for rendering partial view
@Html.Partial("~/Views/Company/CreatePartial.cshtml", Model.companyViewModel, new ViewDataDictionary { TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "companyViewModel" }} );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question