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

Last Reply 4 months ago By bigbear

Posted 4 months ago

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

 

Posted 4 months ago

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