Reputation: 11
I'm using mvc razor.
I want to make all input in <div>
"read only" if they do not have permission at the load of view.
if(!myUser.Permissions("View infor"))
$('div.divMemberLookup :input').readonly(true);
I'm trying to use jQuery readonly plugin.
What is the best way to do this?
Upvotes: 1
Views: 12649
Reputation: 11637
if you want read only (as opposed to disabled) you can do this
$('div input').attr("readonly", "readonly");
one of the differences is that you can select and copy readonly attributes but not disabled ones.
Upvotes: 1
Reputation: 1028
I think the best way would be to generate the input field from the server side code:
In ur Razor page, you have this
@RAW(Model.printInputfield());
on ur Model class you have a method to genarate the input field
public string printInputfield(){
if(!myUser.Permissions("View infor"))
return "<input type='text' disabled:disabled value="ur Values" />";
else
return "<input type='text' value="ur Values" />";
}
Upvotes: 0
Reputation: 4024
add the @
sign in front of your if statement.
@if(!myUser.Permissions("View infor"))
{
$('div.divMemberLookup :input').attr('readonly',true);
}
That way it will only render that JS if the serverside permissions are true.
Upvotes: 0
Reputation: 1248
Does this really need a plugin? Can you not just do something like this:
if(!myUser.Permissions("View infor"))
$('div.divMemberLookup input').attr('disabled',true);
Upvotes: 0