Home > Back-end >  View Component Loading Issue on Production ASP.NET Core
View Component Loading Issue on Production ASP.NET Core

Time:02-25

I am working on an application where I want to load View Component. On local machine it is working with out any problem or error but when I make deployment it is not working properly and gives me error of 500. Here is my implementation.

Jquery Function

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)
        }
    });
      
};

Controller action method

     public IActionResult NotificationHistory()
            {
                return ViewComponent("NotificationHistory");
            }

View Component .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));
        }
    }

View Code

@using GMDSuperAdmin.Helper
@model GMDSuperAdmin.Models.NotificationParentModel

<div mt-5" : "") bg-white px-0">
    <div >
        <h5 >Notification History</h5>
    </div>

    @{
        if (Model.NotificaitonList.Count() > 0)
        {
            foreach (var item in Model.NotificaitonList)
            {
                <div  id="clickable-row">
                   
                    <div  id="translate-row" @*onclick="selectedNotification(this, @item.NOtificationId)"*@>
                        <div >
                            <div >
                                <i ></i>
                            </div>

                            <div >
                                <p >
                                    @item.NotificationDescription
                                </p>
                            </div>
                        </div>
                        
                        <div >
                            <p >
                                @(DateTimeHelper.TimeAgo(item.CreatedDate))
                            </p>
                        </div>
                    </div>
                </div>
            }
        }
        else
        {
            <div  id="clickable-row">

                <div  id="translate-row">
                    <div >
                        <p >
                            <b>No Notification Found!</b>
                        </p>
                    </div>
                </div>
            </div>
        }
    }

</div>

enter image description here

CodePudding user response:

Please rename your view component as default. NotificatioHistory.cshtml to Default.cshtml. Some time it makes issues with custom names on production so the recommended way is to use 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 ... 
        }
    }
  • Related