Well, you
could, if you wanted a messy solution:
public class InsertViewModel
{
...
public bool ReadOnly { get; set; }
}
[HttpGet]
public ActionResult InsertRecord()
{
var model = new InsertViewModel { ReadOnly = false };
return View(model);
}
[HttpGet]
public ActionResult DisplayRecord(int id)
{
var model = GetExistingRecord(id);
model.ReadOnly = true;
return View(nameof(InsertRecord), model);
}
@model InsertViewModel
@{
ViewBag.Title = Model.ReadOnly ? "Record Details" : "Insert Record";
}
@using (Model.ReadOnly ? null : Html.BeginForm())
{
@if (!Model.ReadOnly)
{
@Html.HiddenFor(m => m.ReadOnly)
@Html.AntiForgeryToken()
@Html.ValidationSummary()
}
...
@if (Model.ReadOnly)
{
@Html.DisplayFor(m => m.SomeField)
}
else
{
@Html.EditorFor(m => m.SomeField)
}
...
@if (!Model.ReadOnly)
{
<input type="submit" />
}
}
However, it would be much cleaner to use separate views for inserting and displaying the records.