Question issue when check Resignation requester model properties values it display as null

ahmedaziz

Well-known member
Joined
Feb 22, 2023
Messages
55
Programming Experience
1-3
0
I work on asp.net MVC application . I face issue I can't pass model ResignationRequester properties values to Approve Index action when click approve button .
all properties 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 .
approve button exist on details page so before click approve button submit
I write comments that I need to save it based on request no then click approve button
so How to pass model ResignationRequester to Approve Index action when click approve button
issue on extractio:
@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", new { id = Model.RequestNo }, 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>


    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; }

      


    }

}
public class ResignationController : Controller
    {
[HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> ApprovalIndex(int id)
        {
             return new EmptyResult();
       }
}

I try make some changes to code above as below but issue all properties values as SpeakStuffComment and Request no show null so

How to solve issue please ?

mtor sample:
[HttpPost]
            [ValidateAntiForgeryToken]
            public async Task<ActionResult> ApprovalIndex(ResignationRequester REQ)
            {
                 return new EmptyResult();
           }
  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>
            }

from debug break point cached I check properties value of model Resignation Requester it show it null to all properties values.

so what is issue and How to solve it .
 
Back
Top Bottom