Submitting a Hidden Field with Form post
Submitting a Hidden Field with Form post
pablojoycey
Posts: 3Questions: 1Answers: 0
Hi,
Using data tables along with ASP.NET MVC Razor.
I added Datatables to a form and the form no longer submits a hidden ID field
<div>
<table id="table_id" class="table table-bordered" style="border-bottom: 0px solid #111 !important;border-top: 1px solid whites !important;">
<thead>
<tr>
<th style="border-bottom: 0px solid #111 !important;" class="no-sort">@Html.CheckBox("selectall")</th>
<th style="border-bottom: 0px solid #111 !important;">Name</th>
<th style="border-bottom: 0px solid #111 !important;" class="no-sort">Notes</th>
<th style="border-bottom: 0px solid #111 !important;">Charge<br />per hour</th>
<th style="border-bottom: 0px solid #111 !important;" class="no-sort">Actions</th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.ProjectRows.Count(); i++)
{
@Html.HiddenFor(m => m.ProjectRows[i].ProjectID)
<tr id="row-@i" data-row-index=@i>
<td>@Html.CheckBoxFor(m => m.ProjectRows[i].Selected, new { id = "projectSelector-" + @i, @class = "projectSelector" })</td>
<td>@Html.DisplayFor(m => m.ProjectRows[i].Name)</td>
<td>@Html.Shorten(Model.ProjectRows[i].Notes, MAX_DESC_LENGTH)</td>
ETC....
Any idea how I can get the hidden field to submit?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
If you are trying to put the hidden between the tbody and the tr tags, that is not going to work. Nothing should be between those tags. Have you checked to see if those fields are even there after your page has loaded?
Yes the value is there in source.
If I remove Datatables the postback works just fine.
The problem is that DataTables expects valid HTML and as @bindrid says having an
input
element as the child of atbody
is not valid HTML.You could move the
input
element into the firsttd
in the row and that would make it valid.Allan
Thanks that sorted it