asp.net-mvchtml.textboxfor

To make Textbox write able only after click of Edit button in same View


I have three Textbox which will be in readonly mode like @Html.TextBoxFor(m => m.Whatever, new {@readonly = "readonly"}) when the view will be loaded and one Edit Button. After click on Edit button i want that Textbox to be writeable in same View. Is it possible to use same View or do i have to create another View without @readonly = "readonly" property for TextBox


Solution

  • You can use javascript/jquery to remove the readonly attribute, for example

    @Html.TextBoxFor(m => m.Whatever, new {@readonly = "readonly"})
    <button id="edit" type="button">Edit</button>
    
    $('#edit').click(function() {
        $('#Whatever').prop('readonly', false);
    });