Razor html.raw使用jQuery的数组显示整个数组



想要使用 @Html.Raw 来显示 Html 解码的字符串。

我正在根据正在单击的选项卡显示消息。当我不使用 @Html.Raw 时,一切正常。如果没有 @Html.Raw,我会收到一条带有 @Html.Raw 的消息,我会收到所有 3 条消息。我正在使用jquery来控制正在显示的内容。

如何使用 @Html.Raw 显示 1 条消息,以便显示 Html 解码。

在此处输入图像描述

用于构建阵列的控制逻辑

customerVM.DisplayMessage = new[] { company.Tab_Footer_WebOrder_Message, company.Tab_Footer_Order_Message, company.Tab_Footer_Invoice_Message };

Html@Html.Raw(@Model.DisplayMessage[i]( 应仅根据单击的选项卡显示 1 条消息。

<div>
@for (var i = 0; i < Model.DisplayMessage.Length; i++)
{
<p style="@(i == 0 ? "" : "display: none;")" id="tab-description-@(i + 1)" class="tab-description">@Html.Raw(@Model.DisplayMessage[i])</p>
}
</div>

Jquery

$("#tabs").tabs({
activate: function (event, ui) {
var active = $('#tabs').tabs('option', 'active');
var getTab = $("#tabs ul>li a").eq(active).attr("href");
$(".tab-description").hide();
switch (getTab) {
case "#tabs-1":
$("#tab-description-1").show();
break;
case "#tabs-2":
$("#tab-description-2").show();
break;
case "#tabs-3":
$("#tab-description-3").show();
break;
}
}
})

可能是html.raw助手解释对象的类型。 尝试创建中间变量

<div>
@for (var i = 0; i < Model.DisplayMessage.Length; i++)
{
var tmp=@Model.DisplayMessage[i];
<p style="@(i == 0 ? "" : "display: none;")" id="tab-description-@(i + 1)" class="tab-description">@Html.Raw(tmp)</p>
}
</div>

最新更新