我正在开发 ASP.NET MVC 应用程序。我面临一个问题,即单击“批准”按钮时无法将模型
ResignationRequester
属性值传递给 ApproveIndex
操作方法。
所有属性,如
Request no
和employee 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; }
}
我的所有属性值上方的代码问题为
SpeakStuffComment and Request no
显示为空 - 请问如何解决此问题?
从调试断点,我检查了模型 Resignation Requester 的属性值,尽管它有数据,但所有属性值都显示为空。
那么问题是什么以及如何解决?
您可以提供 ApproveIndex get 和 post 操作代码吗?