所以非常奇怪,下面是警报值:
然而奇怪的是,combineRole上的警报给了我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" })';
}
答案 0 :(得分:4)
删除引号,你不是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" })';
}
答案 1 :(得分:3)
您将consumerSupportEditableRole
和superAdminRole
设置为字符串,而不是布尔值。所以combinedRole
实际上是:
var combinedRole = "true" && "false";
使其成为"false"
,即truthy。