Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML.TextBoxFor disabled not passing value

I have the following bit in my view :

@Html.TextBoxFor(model => model.PersonnelId, new { disabled = "disabled" })

In my controller I have this :

if (ModelState.IsValid)
{
    PersonnelFacade.SavePerson(person);
    return RedirectToAction("Index");
}

Now when I check the person.PersonnelId it is empty. When I remove the {disabled = "disabled" } it works fine but then I can change the PersonnelId which is not what I want to do.

What am I doing wrong?

like image 996
Bart Schelkens Avatar asked Nov 07 '12 10:11

Bart Schelkens


1 Answers

Try 2 values

  1. PersonnelIdForDisplay
  2. PersonnelId

Then on your view

  1. @Html.TextBoxFor(model => model.PersonnelIdForDisplay, new { disabled = "disabled" })
  2. @Html.HiddenFor(p => p.PersonnelId)
like image 96
ELTEE Avatar answered Oct 05 '22 06:10

ELTEE