Click here to Skip to main content
14,241,604 members
Rate this:
Please Sign up or sign in to vote.
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 =>
                              w.TimeSheetMasterId.Equals(masterId)).FirstOrDefault();
            var detailM = context.TimeSheetDetails.Where(t => t.TimeSheetMasterId.Equals(
                              masterModel.TimeSheetMasterId)).FirstOrDefault();
            var project = context.Projects.Where(p => p.ProjectId == 
                              detailM.ProjectId).FirstOrDefault();

            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
                           }).FirstOrDefault();
            return View(details);
        }
        //POST: TimeSheet/AdminApproval{model}{approve}{reject}
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> AdminApproval(TimeSheetDetailsModel model, 
               string btnApprove, string btnReject)
        {
            var master = await context.TimeSheetMaster.Where(m => m.TimeSheetMasterId == 
                         model.TimeSheetMasterId).FirstOrDefaultAsync();

            if(btnApprove != null)
            {

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

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

                            <input type="submit" class="btn btn-danger" value="Reject" name="btnReject" />

                        }


What I have tried:

Tons of ways I tried but NO luck... even tried the commenting ways.
Getting mmy Model in httppost

        [HttpPost]
        public ActionResult AdminApproval(TimeSheetDetailsModel model)
        {
            var master =  context.TimeSheetMaster.Where(m => m.TimeSheetMasterId ==
                         model.TimeSheetMasterId).FirstOrDefaultAsync();
            return RedirectToAction("TimeSheetList");
        }


        public ActionResult ApproveTimeSheet(TimeSheetDetailsModel model)
            //([Bind(Include ="TimeSheetMasterId,UserId")]TimeSheetDetailsModel model)
        {
            return RedirectToAction("TimeSheetList");
        }

        [HttpPost]
        public ActionResult RejectTimeSheet([Bind(Include = "TimeSheetMasterId,UserId")]TimeSheetDetailsModel model)
        {
            return RedirectToAction("Index", "Home");
        }
        //POST: TimeSheet/AdminApproval{model}{approve}{reject}//[ValidateAntiForgeryToken]
        /*[HttpPost]        
        public async Task<ActionResult> AdminApproval(int id, TimeSheetDetailsModel model )
        // ,string btnApprove, string btnReject)
        //{
            var master = await context.TimeSheetMaster.Where(m => m.TimeSheetMasterId ==
                         model.TimeSheetMasterId).FirstOrDefaultAsync();

            //if (btnApprove != null)
            //{

                return RedirectToAction("TimeSheetList");
            //}
 @using (Html.BeginForm())
                        {
                            <input type="submit" value="Approve" name="TimeStat" />
                        }
                        @*using (Html.BeginForm())
                        {*@
                            @*@Html.AntiForgeryToken()*@
                            <input type="submit" class="btn btn-success" value="Approve" name="btnTime" 
                                   formaction="@Url.Action("RejectTimeSheet")" formmethod="post" />

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

                        @* } *@

                        @*@Html.ActionLink("Approve2", "AdminApproval", new { model = Model }, new { @class = "btn btn-success" })*@

                        @*@Html.ActionLink("Reject", "", null, new { @class = "btn btn-danger" })*@

                        @Html.ActionLink("App", "ApproveTimeSheet", new { model = Model })

                        @Html.ActionLink("Rej", "RejectTimeSheet", new { model = Model.TimeSheetMasterId })

                        <a href="@Url.Action("ApproveTimeSheet", "TimeSheet", new { model = Model })">hrefApp</a>
Posted
Comments
Maciej Los 30-Apr-19 5:28am
   
Sorry, but your question is not clear, especially this: "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 have no idea what you're talking about...
Can you be more specific and provide more details about your issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100