Make all form fields only in MVC

I show 3 or more versions of the form. One version is an editing form for editing all fields. The second version will be a read-only version of the same form that will be used to display all the same fields, but with all fields having readonly = "true" on the client side, so that the user can not enter data. For readonly fields, you must use a different css style. It displays archived data. I already hide the submit button so that they cannot submit, but I want the form to look like it is read-only. The third version will have some read-only fields and some editable for a certain class of users with limited editing rights.

I am using ASP.NET MVC 1.0. How to change all (or a subset) of displayed fields so that they are read-only. I would like to iterate through a collection of fields in the controller and set them all to read, and also set the correct css class. I don’t want to include an if statement in every field in the .aspx file (there are 40-50 fields), and I would prefer not to have this on the client side so that I can prevent users from changing javascript / html to edit things that they shouldn't.

TIA

Steve sier

+5
source share
4 answers

, , , .

, jQuery:

$(function() {
  $('input, select, textarea').attr('disabled', 'disabled');
});

, . - bool, ( ViewData, ), , , disabled. ...

+12

, , , . , , . , . , divs , .

. , / , . , , - , , . / , / .

+1

/ .

, ( ):

  • <% Html.RenderPartial(the_right_partial, model); %> the_right_partial - , , ( the_right_partial(something));
  • bool enum paramether , , htmlAttributes, : <%= Html.TextBox("name", value, Html.TheRightHtmlAttributesFor(isReadableOrNot)) %>;

, , isReadableOrNot ( ), html/aspx ( / ), .

, html, disabled, , , firebug, , .

, : , , , ( / , ).

0

Since I am trying to use one partial for different states of the form, I think that I will create auxiliary functions that will be displayed correctly based on the state and user. Helpers will use a field dictionary that will indicate under what conditions the field is read only. I still have server side checks to make sure the data is valid and the user has the right to make changes.

Thanks for all your ideas and help.

Steve

0
source

All Articles