I'm using mvc ra开发者_运维百科zor.
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?
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.
trie this:
$('div input').attr("disabled", true);
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);
jsFiddle Example
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.
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" />";
}
精彩评论