0

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 View Edit

Is it way to resolve this problem?

2 Answers 2

4

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" />
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. This is work. Unfortunately i have not enough reputation to mark your answer as useful. But thx again.
0

Instead Using @Html.EditorForModel() twice use it single time..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.