Redirect to other View based on Button Clicked in ASP.Net MVC

Last Reply on Apr 30, 2019 09:30 PM By bigbear

Posted on Apr 30, 2019 12:04 AM

I have 2 buttons but I cant bring my model to the page and click a button to determine how to set my model. I’m thinking if I can get my model in my page I’ll be able to figure out these buttons possibly.

I tried bring the model like usual new { model = Model} but my model Is still null…

Here is my code 

        // GET: TimeSheet/AdminApproval{masterid}
        public ActionResult AdminApproval(int masterId)
            var masterModel = context.TimeSheetMaster.Where(w =>
            var detailM = context.TimeSheetDetails.Where(t => t.TimeSheetMasterId.Equals(
            var project = context.Projects.Where(p => p.ProjectId == 

            var details = (from master in context.TimeSheetMaster
                           join detail in context.TimeSheetDetails
                           on master.TimeSheetMasterId equals detail.TimeSheetMasterId
                           where master.TimeSheetMasterId == masterId
                           select new TimeSheetDetailsModel()
                               Sunday = detail.Sunday,
                               Monday = detail.Monday,
                               Tuesday = detail.Tuesday,
                               Wednesday = detail.Wednesday,
                               Thursday = detail.Thursday,
                               Friday = detail.Friday,
                               Saturday = detail.Saturday,
                               Hours = detail.Hours,
                               Comment = master.Comment,
                               ProjectName = project.ProjectName
            return View(details);
        //POST: TimeSheet/AdminApproval{model}{approve}{reject}
        public async Task<ActionResult> AdminApproval(TimeSheetDetailsModel model, 
               string btnApprove, string btnReject)
            var master = await context.TimeSheetMaster.Where(m => m.TimeSheetMasterId == 

            if(btnApprove != null)

                return RedirectToAction("TimeSheetList");
            else if(btnReject != null)
                return RedirectToAction("Index", "Home");

            return View();


                        <div class="panel-footer">
                        @using (Html.BeginForm("AdminApproval", "TimeSheet",
                            new { model = Model }, FormMethod.Post))
                            <input type="submit" class="btn btn-success" value="Approve" name="btnApprove" />
                            <input type="submit" class="btn btn-danger" value="Reject" name="btnReject" />


You are viewing reply posted by: bigbear on Apr 30, 2019 09:30 PM.
Posted on Apr 30, 2019 09:30 PM

I ended up using this input and creating custom actions for each input on my beginform

I have 2 submit buttons with [httppost] and I got it working successfully.

<input type="submit" class="btn btn-danger" value="Reject" name="response" formaction="@Url.Action("RejectTimeSheet")" formmethod="post" />