jquery 当点击approve按钮时,如何将所有带值的模型属性传递给索引操作?

wdebmtf2  于 2023-10-17  发布在  jQuery
关注(0)|答案(1)|浏览(88)

我在一个ASP.NET MVC应用程序上工作。我遇到一个问题,当点击“approve”按钮时,我不能将模型ResignationRequester属性值传递给ApproveIndex操作方法。
所有属性,如Request noemployee no加载时,详细信息页面加载,然后我写评论SpeakStuffComment,然后点击“批准”按钮保存SpeakStuffComment基于request no
当我点击“删除”按钮时,如何将模型ResignationRequester传递给ApproveIndex操作方法?

@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>

代码:

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(ResignationRequester REQ)
        {
             return new EmptyResult();
       }
}

当调用API时,它击中了操作结果断点,但值显示为空,我的问题是代码上的所有属性值都显示为空,如SpeakStuffComment and Request no-如何解决这个问题,请?
从调试中断点,我检查了模型的属性值,尽管它有数据,但所有属性值都显示为null。
那么问题是什么,如何解决?

h5qlskok

h5qlskok1#

你能提供ApproveIndex获取和发布操作代码吗?

相关问题