根据我的同事的代码,他在视图中使用BeginForm将HTML属性传递到表单声明中,生成的HTML如下:
<form action="/Reviewer/Complete" ipbID="16743" method="post">
我该如何在控制器代码中获取ipbID?我已尝试过。
HttpContext.Request.QueryString["ipbID"]
... and ...
Request.Form["ipbID"]
我甚至进入调试模式并检查了每个Request.Form的部分,以查看是否存在该值。在表单标记中放置这样的值是否不是一个好习惯?非常感谢您的任何帮助。
更新: 我应该告诉大家,此表单正在应用于单元格。这些单元格位于dataTable中。当我使用时,它返回了隐藏的第一个值,但没有后续的值。
更新2: 视图
<% Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<PTA.Models.IPB>>" %>
<%@ Import Namespace="PTA.Helpers"%>
<b>Assigned IPBs</b>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#sharedIPBGrid').dataTable();
});
</script>
<%
if (Model != null && Model.Count() > 0)
{
%>
<table id="sharedIPBGrid" class="display">
<thead>
<tr>
<th>
<%=Html.LabelFor(m => m.FirstOrDefault().IPBName) %>
</th>
<th>
<%=Html.LabelFor(m => m.FirstOrDefault().Status) %>
</th>
<th>
<%=Html.LabelFor(m => m.FirstOrDefault().PubDate) %>
</th>
<th>
<%=Html.LabelFor(m => m.FirstOrDefault().ChangeDate) %>
</th>
<th>
<%=Html.LabelFor(m => m.FirstOrDefault().Priority) %>
</th>
<th>
<%=Html.LabelFor(m => m.FirstOrDefault().Errors) %>
</th>
<th>
Start
</th>
<th>
Stop
</th>
<th>
Complete
</th>
</tr>
</thead>
<tbody>
<tr>
<%
foreach(IPB ipb in Model)
{
%>
//Ignoring everything except for the Complete button as there's a lot of logic in there.
<td>
<%
if (ipb.StatusID == (int)PTA.Helpers.Constants.State.InWorkActive)
{
using (Html.BeginForm("Complete", "Reviewer", FormMethod.Post, new {ipbID = ipb.ID}))
{
%>
<%=Html.Hidden("ipbID", ipb.ID)%>
<input type="submit" id="btnComplete" value="Complete" />
<%
}
}
%>
</td>
<%
}
%>
</tr>
</tbody>
</table>
<%
}
else
{
Response.Write("No IPBs found!");
}
%>