【发布时间】:2021-04-21 10:34:56
【问题描述】:
我的要求是根据列表中的项目数量在 UI 上显示横幅消息。
在 _Layout 文件上我调用了我的局部视图:
@Html.Partial("~/_Notification.cshtml")
_Notification.cshtml
<div id="outage-notification" class="row" style="display: none;">
<div>
<div>
<div id="notification-content" class="notification-content"></div>
<div class="dismiss-notification"><a class="small noloader" href="javascript: void(0);" >@CommonUIResources.Dismiss</a></div>
</div>
</div>
</div>
@Scripts.Render("~/bundles/outageNotification")
我的 javascript 文件:
var outageNotification;
class OutageNotification {
constructor() {
this.setup();
}
setup() {
var date1 = new Date().toUTCString();
$.ajax({
type: "GET",
url: "Notification/GetBannerNotifications",
data: { dateTime: date1 },
success: function (notificationMessage) {
if (notificationMessage !== undefined && notificationMessage !== "") {
$("#notification-content").append(notificationMessage);
$("#notification").fadeIn("slow");
}
else {
}
}
});
}
}
$(document).ready(() => {
this.outageNotification = new OutageNotification();
});
我的控制器方法:
[HttpGet]
[Route("Notification/GetBannerNotifications")]
public JsonResult GetBannerNotifications(DateTime? dateTime)
{
var listOfStrings = this.notificationService.GetBannerNotifications(dateTime.Value);
return this.Json(listOfStrings, JsonRequestBehavior.AllowGet);
}
下图只包含一个字符串,但如果我有多个字符串,那么它也会在一张图像中显示所有字符串。
它将所有字符串显示为单个字符串并在 UI 中显示该字符串。
但我需要多次显示此图像取决于列表中的多个字符串。
【问题讨论】:
标签: javascript c# .net asp.net-mvc asp.net-core