Form in the view with sub-forms in partialView

2

Dear friends, I have a view that contains only @model Projeto.Models.Oc and a form . Within this form , I have buttons that call MODAL , these MODAL have partialView , @model Projeto.Models.Rc , etc.

I wanted to know how to handle this need, as I believe that these strong type in @model Projeto.Models.Pc main% and view are conflicting.

    
asked by anonymous 07.04.2014 / 15:12

2 answers

2

The <form> should always only stay in the parent View. Partial Views may even have fields of <form> , but within them you can not use <form> , even because HTML does not even put <form> inside another.

As for specifying the strong types for each partial , there are no problems as long as for each partial the correct type is passed. That is, I suppose for the View parent, it has the following statement:

@model Projeto.Models.Oc

partials is called this:

@Html.Partial("_MinhaPartial", Model.Rc)

Or so:

@Html.Partial("_MinhaPartial", new Projeto.Models.Rc())
    
07.04.2014 / 16:10
1

Create properties in your main model of the type of models that will be loaded into your partials. So you just need to reference a single model in your view, regardless of what your partials views might load. For example:

public class ModelPrincipal
{
   //Depois de você declarar as propriedades dessa model, 
   //declare a propriedade da model que trabalhara na partial View
   public ModelSecundaria modelSecundaria {get; set;}

}

After that feed your model into your Action, according to your business and refer to it in your PartialView as if it were a normal property:

 @Html.Partial("_MyPartial", Model.modelSecundaria);
    
07.04.2014 / 16:15