When I debug through my code I am getting a null value for the 'review' parameter in the Post EmployeeReviewEdit method. When I walk through the HttpGET method the return value of 'review' looks correct and eveything is populated correctly in the view but when I post back to to the action the parameter is null and i can't seem to figure it out why.
Here are my GET and POST actions:
[HttpGet]
public ActionResult EmployeeReviewEdit(int id, string employeeName)
{
ViewBag.EmployeeName = employeeName;
var review = _employeeDb.EmployeeReviews.Find(id);
var cono = _employeeDb.EmployeeMasters.FirstOrDefault(e => e.EmployeeNumber == review.EmployeeNo).CompanyNumber;
var list = _selectListLib.GetManagers((int)cono,Convert.ToInt32(review.ReviewBy));
ViewBag.ManagerList = list;
return View(review);
}
[HttpPost]
public ActionResult EmployeeReviewEdit(EmployeeReview review)
{
_dbDataManipulation.UpdateEmployeeReview((int)review.EmployeeNo,(DateTime) review.ReviewDate, review.ReviewBy, CurrentUserName(), review.Id);
return RedirectToAction("EmployeeReview", new { empNo = review.EmployeeNo});
}
Here is my View:
@model EmployeeMaster.Models.EmployeeReview
@{
ViewBag.Title = "EmployeeReviewEdit";
}
@section scripts
{
<script type="text/javascript">
$(function () {
$('#ReviewDate').datepicker();
});
</script>
}
<div id="results-container" style="background-color: #c9c9c9; padding: 10px; margin-top: 40px;">
<h2>@ViewBag.EmployeeName - Edit Review</h2>
<div style="background-color: #9e2b3c; padding: 1px; margin-bottom: 10px"></div>
@using (Html.BeginForm("EmployeeReviewEdit","Employee", FormMethod.Post, new{@id = "review-edit-form"}))
{
@Html.Label("Review Date: ", new { id = "reviewdate-label" })
@Html.TextBoxFor(model => model.ReviewDate,"{0:d}", new { @class = "form-control" })
@Html.Label("Review By: ", new { id = "reviewby-label" })
@Html.DropDownListFor(model => model.ReviewBy, (List < SelectListItem >)ViewBag.ManagerList, new { @class = "form-control" })
@Html.HiddenFor(model => model.EmployeeNo)
@Html.HiddenFor(model => model.CreatedBy)
@Html.HiddenFor(model => model.CreatedOn)
@Html.HiddenFor(model => model.ModifiedBy)
@Html.HiddenFor(model => model.ModifiedOn)
@Html.HiddenFor(model => model.Id)
<input type="submit" name="review" class="col-sm-1 btn btn-default" id="edit-button"value="Save" />
}
</div>
My issue was that my input control had a name "review" which was causing confusion to my parameter which is also called "review" i changed the name of the input[submit].
input[type=submit]'snameattribute caused a conflict with your parameter name is not obvious and is interesting (I didn't know that could happen). You should post your solution as an answer and accept it.