I found some examples of a combination of Razor Syntax and jQuery. For example:
Jquery syntax in .cshtml file Razor View Engine and jQuery
What am I do trying to do? I set a Class called "MaxHeight" on the tr, but the user should only be enabled to click a Checkbox if he clicked on the + Button AND is on a Usergroup.
So my jQuery-tinkerings looks like this:
function SizeButtonClicked(obj) {
var closestTr = $(obj).closest('tr');
if (closestTr.hasClass('maxHeight')) {
closestTr.removeClass('maxHeight');
@if(Roles.IsUserInRole(UserRole.Customer.ToString()) || User.IsInRole(UserRole.Admin.ToString()))
{
<text>
<script type="text/javascript">
closestTr.find('input[type=checkbox]').removeAttr('disabled');
</script>
</text>
}
}
else {
closestTr.addClass('maxHeight');
closestTr.find('input[type=checkbox]').attr('disabled', 'disabled');
}
}
So if the user is in the Role Customer or Admin, I'd like to remove the attr disabled and he is enabled to click the CHK.
But I guess this won't work in 1000 Years. Is it even possible to combine stuff like this? Would there be a easier solution for such Ideas?
Edith: I try to use what Warrior and Sergey said, so I made a own JS-File and pass a Parameter to check if the disabled attribute should be searched:
<input type="button" value="+" class="SizeButton" onclick="SizeButtonClicked(this, @(Roles.IsUserInRole(UserRole.Customer.ToString()) || User.IsInRole(UserRole.Admin.ToString())))" />
Does not work so far, but would something like this BE the solution for proper programming?