Reputation: 486
I tried to render model in View with Html.EditorForModel.
This is code of my Model.
Product class
public class Product
{
[Key]
[HiddenInput(DisplayValue = false)]
public int ProductId { get; set; }
public string Name { get; set; }
public string Model { get; set; }
public string Serial { get; set; }
[HiddenInput(DisplayValue = false)]
public int DealerId { get; set; }
[ForeignKey("DealerId")]
public virtual Dealer Dealer { get; set; }
}
Dealer class
public class Dealer
{
[Key]
public int DealerId { get; set; }
public string Name { get; set; }
public int DealerNumber { get; set; }
}
I try do render Product for editing. I do it this way
@using (Html.BeginForm("Edit","Product"))
{
@Html.EditorForModel()
@Html.EditorForModel(Model.Dealer)
<input class="btn btn-default" type="submit" value="edit" />
}
But it seems like View render EditorForModel() twice. This is screen
Is it way to resolve this problem?
Upvotes: 0
Views: 1582
Reputation: 4381
Indeed you're calling @Html.EditorForModel
twice. Try this instead :
@using (Html.BeginForm("Edit","Product"))
{
@Html.EditorForModel()
@Html.EditorFor(model => model.Dealer)
<input class="btn btn-default" type="submit" value="edit" />
}
Upvotes: 4