Asked by:
How to show a grid view light box on a razor view

Question
-
User-259252065 posted
I'm implementing asp.net core project. I have an Index razor view that has some columns and a link called Details for each row. I want when the user clicks on Details link, some related data for that rows goes to display on a lightbox I mean the lightbox will display some columns (grid view). Now what I have tried is when the user clicks on Details link, it goes to the related method in the controller and returns its related view. But as I mentioned I want the details method returns a lightbox which hide the below index view. I appreciate if anyone suggests me a solution to solve it.The code in Index view I tried is like the following:@model IEnumerable<CSDDashboard.TempClasses.itemApplicantDTO> <div id="tablecontainer" class="my-5 col-sm-12 d-flex justify-content-center"> <table id="myDummyTable" class="table m-table mytable table-striped mb-4 col-12 dataTable table-bordered px-0 mx-0" style="box-sizing:content-box;"> <thead> <tr id="headerrow"> <th> applicant name </th> <th> requested item count </th> <th> Delivered items </th> <th> pending item </th> <th> in process item </th> <th> operations </th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.applicantName) </td> <td> @Html.DisplayFor(modelItem => item.requestedItemCount) </td> <td> @Html.DisplayFor(modelItem => item.deliveredItemCount) </td> <td> @Html.DisplayFor(modelItem => item.pendingItemCount) </td> <td> @Html.DisplayFor(modelItem => item.inProcessItemCount) </td> <td> <a asp-action="Edit" asp-route-id="@item.applicantID">Edit</a> | <a asp-action="Details" asp-route-id="@item.applicantID">Details</a> | <a asp-action="Delete" asp-route-id="@item.applicantID">Delete</a> </td> </tr> } </tbody> </table> </div>
Index method in the controller:public async Task<IActionResult> Index(string searchString, string currentFilter, string sortOrder, int? pageNumber){ApiApplicantDTO tempObject;List<ApiApplicantDTO> myArrList = new List<ApiApplicantDTO>();var applicants = (from t1 in _context.VwReport.ToList()group t1 by new { t1.ApplicantId, t1.ApplicantName } into ApiAppGpselect new{applicantID = ApiAppGp.Key.ApplicantId,applicantName = ApiAppGp.Key.ApplicantName,deliveredApiCount = (ApiAppGp.ToList().Where(a => a.LastReqStatus == "access")?.Count() ?? 0),inProcessApiCount = (ApiAppGp.ToList().Where(a => a.LastReqStatus == "registered")?.Count() ?? 0),pendingApiCount = (ApiAppGp.ToList().Where(a => a.LastReqStatus == "pending")?.Count() ?? 0),apicount = ApiAppGp.Count(),}).ToList();for (int i = 0; i < applicants.Count(); i++){tempObject = new ApiApplicantDTO();tempObject.applicantID = applicants.ElementAt(i).applicantID;tempObject.applicantName = applicants.ElementAt(i).applicantName;tempObject.deliveredApiCount = applicants.ElementAt(i).deliveredApiCount;tempObject.inProcessApiCount = applicants.ElementAt(i).inProcessApiCount;tempObject.pendingApiCount = applicants.ElementAt(i).pendingApiCount;tempObject.requestedApiCount = applicants.ElementAt(i).apicount;myArrList.Add(tempObject);}return View(myArrList);//.ToListAsync());}
Details method in the controller:public async Task<IActionResult> Details(int? id){List<ApiApplicantDTO> al = new List<ApiApplicantDTO>();ApiApplicantDTO apDTO;var myquery = (from t in _context.VwReportwhere t.ApplicantId==idselect new { apiName = t.ApiName,applicantName=t.ApplicantName,requestStatus=t.LastReqStatus }).ToList();foreach(var index in myquery){apDTO = new ApiApplicantDTO();apDTO.apiName = index.apiName;apDTO.applicantName = index.applicantName;apDTO.requestStatus = index.requestStatus;al.Add(apDTO);}return View(al);
}Saturday, August 8, 2020 11:50 AM
All replies
-
User711641945 posted
Hi Elenorarez,
It seems your requirement is like this thread below:
https://stackoverflow.com/a/63335732/11398810
And in this case solution,no need Details action,just using the Index action.Add the hidden div which could display the details in your Index.cshtml.
Best Regards,
Rena
Monday, August 10, 2020 8:27 AM