I work on an ASP.NET MVC application. I face an issue that I can't pass model ResignationRequester
properties values to ApproveIndex
action method when clicking on the "approve" button.
All properties such as Request no
and employee no
load when details page load then I write comment SpeakStuffComment
then click "approve" button to save SpeakStuffComment
based on request no
.
How to pass model ResignationRequester
to ApproveIndex
action method when I click the "Approve" button?
@model HR.WorkforceRequisition.Models.ResignationRequester
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_LayoutResignation.cshtml";
}
<div style="padding-top:10px;">
@if (!string.IsNullOrEmpty(ViewBag.msg))
{
<div class="alert alert-success">
@ViewBag.msg
</div>
}
@if (ViewBag.AllowApprove == true)
{
using (Html.BeginForm("ApprovalIndex", "Resignation", FormMethod.Post, htmlAttributes: new { @style = "display:inline;" }))
{
@Html.AntiForgeryToken()
<a onclick = "$(this).parents('form:first').submit();" class="btn btn-primary" style="min-width: 100px;
margin-left: 5px;"><i class="glyphicon glyphicon-ok"></i> Approve </a>
}
<table style="border: 1px solid black;width:100%;">
<tr>
<td class="hover" style="font-weight: bold; padding-top: 10px;">
<div class="form-group hover">
@Html.LabelFor(model => model.RequestNo, htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-7">
@Model.RequestNo
</div>
</div>
</td>
</tr>
<tr>
<td class="hover" style="width: 50%; font-weight: bold; padding-top: 10px;">
@Html.LabelFor(model => model.EmpName, htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-7">
@Model.EmpName
</div>
</td>
<td class="hover" style="font-weight: bold; padding-top: 10px;">
@Html.LabelFor(model => model.EmpID, htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-7">
@Model.EmpID
</div>
</td>
</tr>
</table>
<table style="border: 1px solid black;width:100%;">
<tr>
<td class="hover" style="font-weight: bold; padding-top: 10px;">
<div class="form-group hover">
@Html.Label("If yes, why did the staff resign? If No, Why? ", htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-7">
@Html.EditorFor(model => model.SpeakStuffComment, new
{
htmlAttributes = new
{ @class = "form-control" }
})
</div>
</div>
</td>
</tr>
</table>
</div>
Code:
public class ResignationRequester
{
[Display(Name = "Employee No : ")]
[Required,]
public int EmpID { get; set; }
[Display(Name = "Request No")]
public int RequestNo { get; set; }
[Required]
[Display(Name = "Emp. Name: ")]
public string EmpName { get; set; }
[DataType(DataType.MultilineText)]
public string SpeakStuffComment { get; set; }
}
Approve index action as below :
public class ResignationController : Controller
{
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ApprovalIndex(ResignationRequester REQ)
{
return new EmptyResult();
}
}
when call API it hit action result break point but values display as null
my issue on code above all properties values as SpeakStuffComment and Request no
show null - how to solve this issue, please?
From debug break point, I checked properties value of model Resignation Requester it show it null for all properties values although it have data.
So what is issue and how to solve it?