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
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);
}
[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)
{
return RedirectToAction("TimeSheetList");
}
[HttpPost]
public ActionResult RejectTimeSheet([Bind(Include = "TimeSheetMasterId,UserId")]TimeSheetDetailsModel model)
{
return RedirectToAction("Index", "Home");
}