Form in view with subforms in partialView

Asked

Viewed 217 times

2

Dear friends, I have a view containing only @model Projeto.Models.Oc and a form. Within this form, I have buttons that call MODAL, those MODAL possess partialView who owns another form and @model Projeto.Models.Rc, @model Projeto.Models.Pc, etc..

I wanted to know what the deal is for this need, because I believe that these Strong type in view main and in the partialViews are conflicting.

2 answers

2


The <form> should always be only in the parent view. Partial views may even have <form>, but within them you can not use <form>, even because HTML doesn’t even put a <form> within another.

As to specify the strong types for each partial, there are no problems, since for each partial the right kind. That is, I suppose for the View father, who has the following statement:

@model Projeto.Models.Oc

As partials be called so:

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

Or so:

@Html.Partial("_MinhaPartial", new Projeto.Models.Rc())
  • Gypsy, I’m using the Create view as I said above, but in the Edit view, I need to pass the ticket parameter so that partialView is filled in. How can I do this?

  • In this case, you create a Viewmodel, which is a class with the class which was previously declared as @model inside, one more Property calling for Ticket. In the POST, Your Controller takes this as a parameter Viewmodel.

1

Create properties in your main model of the models that will be loaded in your partitals. So you only need to reference a single model in your view, regardless of what your partials views can 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 in your Action your model, according to your business and refer in your Partialview as if it were a normal property:

 @Html.Partial("_MyPartial", Model.modelSecundaria);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.