I'm wanting to update a record in my database which has two values, one is the ID, and one is the "description". The ID can never be changed, however I'm relying on the use of strongly-typed features to do it. So, I have the following:
Inherits="System.Web.Mvc.ViewPage<Business>"
Which is fine as it allows me to get everything back. The problem is when I use the following line:
<%= Html.TextBox("BusinessID", ViewData.Model.BusinessID, new { disabled = "disabled", style = "width:50px;", @class = "uppercase", maxlength = "4" })%>
With the disabled = "disabled"
option it doesn't recognise the BusinessID and therefore doesn't pass it back to the controller which, in turn has problems binding the object up.
Not that you'll need it, but here's the controller action:
[HttpPost]
public ActionResult EditBusiness(Business business)
{
if (!ModelState.IsValid)
return View(business);
// update business here
_contractsControlRepository.UpdateBusiness(business);
return RedirectToAction("Businesses");
}
Any ideas why this is happening? I didn't realise form elements were completely hidden on postback when they're disabled. I don't want the users editing that particular field. I've also tried Html.DisplayFor(b=>b.BusinessID)
without any luck.