pajasv
pajasv

Reputation: 111

ASP .NET how to disable input into textboxfor

I need to edit just few properties in my project, so I want to diable input into other textbox (it's already filled with informations).

Example:

@Html.ValidationSummary()
@using (Html.BeginForm("Uprav", "Dnes", FormMethod.Post, new { @class = 
"form-horizontal" }))
{
@Html.HiddenFor(x => x.Id)

<div class="form-group ">
    <label class="col-sm-2 control-label warning">Registrační číslo:</label>
    <div class="col-sm-2 ">
        @Html.TextBoxFor(x => x.Reg_cislo, new { @class = "form-control" })
        @Html.ValidationMessageFor(x => x.Reg_cislo)
    </div>
</div>

Filled from model:

@model ClassLibrary1.Model.Kolobezka

Could anyone help me please?

Upvotes: 0

Views: 2679

Answers (1)

scgough
scgough

Reputation: 5252

Try adding the readonly attribute:

<div class="form-group ">
    <label class="col-sm-2 control-label warning">Registrační číslo:</label>
    <div class="col-sm-2 ">
        @Html.TextBoxFor(x => x.Reg_cislo, new { @class = "form-control", @readonly = "true" })
        @Html.ValidationMessageFor(x => x.Reg_cislo)
    </div>
</div>

When the form is submitted you will obviously have to ignore that field server-side too (as 'readonly' won't stop someone inspecting, changing the value in the field and submitting data for that field)

Upvotes: 1

Related Questions