2 Replies - 173 Views - Last Post: 02 May 2019 - 06:05 PM

#1 Exceedinglife   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 226
  • Joined: 01-July 12

Display data in view depending on button click on mvc5

Posted 30 April 2019 - 08:21 PM

So 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 Here is my code to open my view with everything. Or would I have to create a new view with the same style and have a new action with my specific linq query to do this? 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());
        }

.

Is This A Good Question/Topic? 0
  • +

Replies To: Display data in view depending on button click on mvc5

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6823
  • View blog
  • Posts: 28,274
  • Joined: 12-December 12

Re: Display data in view depending on button click on mvc5

Posted 30 April 2019 - 11:38 PM

I am not sure if I have understood your question, but you can open a named view return View("Orders", Orders);
Was This Post Helpful? 1
  • +
  • -

#3 Exceedinglife   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 226
  • Joined: 01-July 12

Re: Display data in view depending on button click on mvc5

Posted 02 May 2019 - 06:05 PM

You were right I ended up solving it using this.
Thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1