1
I’m having trouble creating the logic of registering models that has relationship between them. One exists only the reference, but in the other the reference is of type List<>.
I created a partialview containing only the field, however, I can not make the screen to be shown to perform the registration. Several errors have already been shown: nullreferenceexception, the model is x, but waits for type y, etc.
I’ve been two days on this assignment!!
Could someone help me to assemble the logic of the record? I mean, including the views and partials views??
Model 1
public Guid Id { get; set; }
[Display(Name = "Nome")]
public string Nome { get; set; }
[Display(Name = "Campo2")]
public string Campo2 { get; set; }
[Display(Name = "MeuEnum")]
public MeuEnum MeuEnum { get; set; }
public IList<Model2> Model2 { get; set; } = new List<Model2>();
Model 2
public Guid Id { get; set; }
[Display(Name = "MeuOutroEnum")]
public MeuOutroEnum Tipo { get; set; }
public virtual Model1 Model1 { get; set; }
My view Create
//Os campos do model1....
@Html.Partial("_PartialModel2", Model.Model2)
My partial view
@model List<MeuProjeto.Presentation.Web.Modelos.Model2>
@foreach (var item in Model)
{
<div class="form-group">
@Html.LabelFor(model => item.MeuOutroEnum, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => item.Tipo, new SelectList(Model[0].Tipo))
@Html.ValidationMessageFor(model => item.Tipo, "", new { @class = "text-danger" })
</div>
}