我正在開發一個要加載視圖組件的應用程式。在本地機器上它沒有任何問題或錯誤,但是當我進行部署時它無法正常作業并給我500錯誤。這是我的實作。
jQuery 函式
function UPdateHistoryGrid() {
$("#notification-history").empty();
var _url = '@Url.Action("NotificationHistory", "Notification")';
$.ajax({
type: "GET",
url: _url,
success: function (result) {
$("#notification-history").html(result);
},
error(res) {
console.log(res)
}
});
};
控制器動作方法
public IActionResult NotificationHistory()
{
return ViewComponent("NotificationHistory");
}
查看組件 .cs
public class NotificationHistoryViewComponent : ViewComponent
{
protected readonly IHttpNetClientService _apiService;
IUserProfileInfoProvider _userInfoProvider;
public NotificationHistoryViewComponent(IHttpNetClientService HttpService,
IUserProfileInfoProvider userInfo)
{
_apiService = HttpService;
_userInfoProvider = userInfo;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = new NotificationParentModel();
var NotificationApiJsonResult = await _apiService.GetAllAsync(Notification_API_URL.GetAllNotificationsHistory.GetEnumDescription(), _userInfoProvider.GetUserInfo().Id, _userInfoProvider.GetToken());
var notificationData = JsonConvert.DeserializeObject<ResponseDTO<IEnumerable<GMDNotificationDTO>>>(NotificationApiJsonResult);
model.NotificaitonList = notificationData.Data.ToList();
return await Task.FromResult((IViewComponentResult)View("NotificationHistory", model));
}
}
查看代碼
@using GMDSuperAdmin.Helper
@model GMDSuperAdmin.Models.NotificationParentModel
<div class="notificationCard-Container text-container @(!Model.IsToday ? "mt-5" : "") bg-white px-0">
<div class="position-relative">
<h5 class="text-center py-3">Notification History</h5>
</div>
@{
if (Model.NotificaitonList.Count() > 0)
{
foreach (var item in Model.NotificaitonList)
{
<div class="row message-row message-row-2 mx-0 py-1" id="clickable-row">
<div class="row mx-0 main-notificationRow justify-content-between" id="translate-row" @*onclick="selectedNotification(this, @item.NOtificationId)"*@>
<div class="d-flex align-items-center py-2">
<div class="notification-list_img document-noti mx-2 mt-1 mx-lg-3">
<i class="fas fa-file-alt"></i>
</div>
<div class="notifierInfo">
<p class="message-paragraph mb-0">
@item.NotificationDescription
</p>
</div>
</div>
<div class="notification-time pt-1 pb-2 mx-2">
<p class="message-paragraph text-right mb-0">
@(DateTimeHelper.TimeAgo(item.CreatedDate))
</p>
</div>
</div>
</div>
}
}
else
{
<div class="row message-row py-1 mx-0" id="clickable-row">
<div class="row mx-0 main-notificationRow" id="translate-row">
<div class="col-12 col-lg-12">
<p class="message-paragraph text-muted mb-0 text-center">
<b>No Notification Found!</b>
</p>
</div>
</div>
</div>
}
}
</div>

uj5u.com熱心網友回復:
請將您的視圖組件重命名為default。NotificatioHistory.cshtml到Default.cshtml。有時它會在生產中使用自定義名稱,因此推薦的方法是使用Default.cshtml。
public class NotificationHistoryViewComponent : ViewComponent
{
protected readonly IHttpNetClientService _apiService;
IUserProfileInfoProvider _userInfoProvider;
public NotificationHistoryViewComponent(IHttpNetClientService HttpService,
IUserProfileInfoProvider userInfo)
{
_apiService = HttpService;
_userInfoProvider = userInfo;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = new NotificationParentModel();
var NotificationApiJsonResult = await _apiService.GetAllAsync(Notification_API_URL.GetAllNotificationsHistory.GetEnumDescription(),
_userInfoProvider.GetUserInfo().Id, _userInfoProvider.GetToken());
var notificationData = JsonConvert.DeserializeObject<ResponseDTO<IEnumerable<GMDNotificationDTO>>>(NotificationApiJsonResult);
model.NotificaitonList = notificationData.Data.ToList();
return View(model); //// Change this ...
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/432861.html
標籤:asp.net-mvc asp.net 核心
上一篇:使用ASP.NETMVC中的DTO和API將資料從控制器發送到視圖
下一篇:為什么我不能格式化sql日期?
