所以很奇怪的是,警报值如下:


ConsumerSupportEditableRole = true
superAdminRole =假
CombinedRole =假


但是,奇怪的是,combinedRole上的警报为我提供了consumerSupport / ConsumerContact / GetEmailLog。所以在if块中运行是出于某种不可思议的原因。我希望它能
转到else块,警报应吐出Implementation / Organization / GetEmailLog

var consumerSupportEditableRole = '@(Roles.IsUserInRole("Consumer Support Editable") ? "true" : "false")';
var superAdminRole = '@(Roles.IsUserInRole("Super Admin") ? "false" : "true")';
var combinedRole = consumerSupportEditableRole && superAdminRole
alert("consumerSupportEditableRole: " + consumerSupportEditableRole);
alert("superAdminRole: " + superAdminRole);
alert("superAdminRole && consumerSupportEditableRole: " + combinedRole);
if (combinedRole)
{
    var url = '@Url.Action("GetEmailLog", "ConsumerContact", new { Area = "ConsumerSupport" })';
}
else
{
    var url = '@Url.Action("GetEmailLog", "Organization", new { Area = "Implementation" })';
}

最佳答案

删除引号,在JS中不是布尔值,而是字符串

var consumerSupportEditableRole = @(Roles.IsUserInRole("Consumer Support Editable") ? "true" : "false");
var superAdminRole = @(Roles.IsUserInRole("Super Admin") ? "false" : "true");
var combinedRole = consumerSupportEditableRole && superAdminRole
alert("consumerSupportEditableRole: " + consumerSupportEditableRole);
alert("superAdminRole: " + superAdminRole);
alert("superAdminRole && consumerSupportEditableRole: " + combinedRole);
if (combinedRole)
{
    var url = '@Url.Action("GetEmailLog", "ConsumerContact", new { Area = "ConsumerSupport" })';
}
else
{
    var url = '@Url.Action("GetEmailLog", "Organization", new { Area = "Implementation" })';
}

10-08 00:56