Based on my colleague’s code, he passes the HTML attributes to his form declaration in the view using BeginForm, and the resulting HTML looks like this:
<form action="/Reviewer/Complete" ipbID="16743" method="post">
How can I get ipbID in my controller code? I'm trying to
HttpContext.Request.QueryString["ipbID"]
... and ...
Request.Form["ipbID"]
and I even went into debugging and went through each part of Request.Form to find out if this value was somehow. Should you use such values in a form tag? Any help is appreciated. Thank.
UPDATE: I must inform you that this form applies to the cell. Cells are in dataTable. When I use it, the first value that was hidden, but not one of the following, is returned.
UPDATE 2: View
<% 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 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!");
}
%>