I'd like to use the same partial view to both display a record and edit a record. The layout will be the same for both functions and it seems much cleaner than having an EditRecord partial view and a DisplayRecord partial view. Maintenance will be much easier if I only have one partial view to update.
I'm using this right now and it works:
<div class="editor-label">
@Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
@if (@ViewBag.ViewMode == "display")
{
@Html.DisplayFor(model => model.FirstName)
}
else
{
@Html.EditorFor(model => model.FirstName)
}
@Html.ValidationMessageFor(model => model.FirstName)
</div>
Is there a better way to do it?
Thanks.