1

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?

4
  • action result ApprovalIndex as below : public class ResignationController : Controller { [ValidateAntiForgeryToken] public async Task<ActionResult> ApprovalIndex(int id) { return new EmptyResult(); } } Commented Oct 10, 2023 at 18:11
  • i add it on comment because i can't add it on original post Commented Oct 10, 2023 at 18:12
  • and action result for approveindex is post Commented Oct 10, 2023 at 18:21
  • i update my original post Commented Oct 11, 2023 at 8:12

1 Answer 1

1

Can you please deliver ApproveIndex get and post actions code?

6
  • action result ApprovalIndex as below : public class ResignationController : Controller { [ValidateAntiForgeryToken] public async Task<ActionResult> ApprovalIndex(int id) { return new EmptyResult(); } } Commented Oct 10, 2023 at 18:12
  • Is it all the code of your actions? You use parameter "id" but no code uses it. To my understanding your POST action should receive an object of Model or ViewModel as parameter to handle it's values. Have you checked "Network" on Dev Tools in the browser? What's being sent from your form?
    – kkkristo
    Commented Oct 10, 2023 at 18:54
  • yes post action result and i need to send all requester index model as paramter Commented Oct 10, 2023 at 19:04
  • so can you help me please and if you need any information i will give Commented Oct 10, 2023 at 19:31
  • so what i do to solve this issue please Commented Oct 11, 2023 at 6:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.