Display data in View based on Button Click in ASP.Net MVC

on Apr 30, 2019 09:24 PM

I have a view that opens on a button click and it displays the data from the action that is being called.

Is there a way I can open up the same view with a set of data in a model from a different controller action.

I have all my timesheets opening on my AdminTimeMenu action. I want only the approved timesheets to open in the same view with a different linq set of criteria on the query.

I know I could easily do it like this but I was wondering if I didn’t have to recreate the view. 

        public async Task<ActionResult> AdminTimeMenu()
            var userTimeSheets = (from times in context.TimeSheetMaster                                  
                                  select new TimeSheetMasterModel()
                                      TimeSheetMasterId = times.TimeSheetMasterId,
                                      FromDate = ((DateTime)times.FromDate),
                                      ToDate = ((DateTime)times.ToDate),
                                      TimeSheetStatus = times.TimeSheetStatus,
                                      TotalHours = times.TotalHours,
                                      Comment = times.Comment,
                                      DateCreated = ((DateTime)times.DateCreated),
                                      UserId = times.UserId.ToString(),
                                      IdShortened = times.UserId.Substring(0, 8)                                      
            if (userTimeSheets == null)
                return HttpNotFound();

            return View(await userTimeSheets.ToListAsync());


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on May 02, 2019 08:01 PM

I solved it with this. I just had to call my view name and put the model in it

return View("AdminTimeMenu", approvals);

For this speciic one i did userTimeSheets