I have an edit view that I want to only allow certain fields to be edited and updated. My issue, for appearance reasons I want the non editable field to be text only without a textbox around them.
This value I do not want to update and want it displayed just as text.
Model.Address<\/code> is correct.
Is there anyway I can use
@Model.Customer<\/code> and keep the
Model.Customer<\/code> data when posting to the controller or am I stuck using the
@Html.TextBoxFor(m => m.Customer)<\/code> to make this work correctly?
public ActionResult CreateExisting(int id)
{
var LO = db.LOes.Find(id);
return View(LO);
}
[HttpPost]
public ActionResult CreateExisting(int id, LO lo)
{
try
{
db.Entry(lo).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index", "LO");
}
catch
{
return RedirectToAction("Error", new { id = id });
}
}
try to add html.hiddenfor
@using (Html.BeginForm("CreateExisting", "..your controller", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model=> model.ID);
<table style="width:800px">
<tr>
<td>
@Html.DisplayFor(model => model.Customer)
</td>
<td>
@Html.TextBoxFor(model => model.Address)
</td>
</tr>
</table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.