I have a table and within each row I have one submit button, I want to submit the data of that row via HTTP POST. I've written my code but the form doesn't render. I am trying to render form each row so I can pass the row values. I am using GridMVC to render my table.
View
@model Business.Models.Administration.StatsImerptsViewModel
@using GridMvc.Html
<h2>Application Stages portal</h2>
<table>
<tr>
<td>
IMechE Date:
</td>
<td>@Html.DropDownListFor(m => m.IMecheData, Model.ListOfYears)
</td>
<td>
<input type="submit" value="View/Amend" />
</td>
</tr>
</table>
<br />
<div id="grid-wrap" style="width: 500px;">
@Html.Grid(Model.CouncilRegistrationReports).Named("ApplicationsGrid").Columns(columns =>
{
columns
.Add()
.Titled("Start Date")
.Filterable(true)
.Format("{0:dd/MM/yyyy}")
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@Html.TextBoxFor(t => m.StartDate, "{0:dd/MM/yyyy}", new { @class = "datepicker" })
);
columns
.Add()
.Titled("End Date")
.Filterable(true)
.Format("{0:dd/MM/yyyy}")
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@Html.TextBoxFor(t => m.EndDate, "{0:dd/MM/yyyy}", new { @class = "datepicker" })
);
columns
.Add()
.Titled("Date sent to EC")
.Filterable(true)
.Format("{0:dd/MM/yyyy}")
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@Html.TextBoxFor(t => m.ECDate, "{0:dd/MM/yyyy}", new { @class = "datepicker" })
);
columns
.Add()
.Titled("CEng")
.Filterable(true)
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@Html.TextBoxFor(t => m.CEng)
);
columns
.Add()
.Titled("IEng")
.Filterable(true)
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@Html.TextBoxFor(t => m.IEng)
);
columns
.Add()
.Titled("EngTech")
.Filterable(true)
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@Html.TextBoxFor(t => m.EngTech)
);
columns
.Add()
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@<b>
@* @Html.ActionLink("Update", "UpdateStatsImerpts", routeValues: new { Id = m.Id, StartDate = m.StartDate, EndDate = m.EndDate, ECDate = m.ECDate, CEng = m.CEng, IEng = m.IEng, EngTech = m.EngTech },
htmlAttributes: new { onclick = "", Id = m.Id })*@
@using (Html.BeginForm("StatsImerpts", "Administration", new { m = m }))
{
<input type="submit" value="Update" />
}
</b>
);
columns
.Add()
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@<b> <a href="@Url.Action("DeleteStatsImerpts", "Administration", routeValues: new { Id = m.Id })" id="@m.Id">
<img src="../../Images/delete.gif" alt="Delete" />
</a></b>
);
}).WithPaging(50)
</div>
<script>
$(function () {
$(".datepicker").datepicker({
changeMonth: true,
changeYear: true
});
});
</script>
HTML where I am trying to use html.beginForm()
@Html.TextBoxFor(t => m.EngTech)
);
columns
.Add()
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@<b>
@* @Html.ActionLink("Update", "UpdateStatsImerpts", routeValues: new { Id = m.Id, StartDate = m.StartDate, EndDate = m.EndDate, ECDate = m.ECDate, CEng = m.CEng, IEng = m.IEng, EngTech = m.EngTech },
htmlAttributes: new { onclick = "", Id = m.Id })*@
@using (Html.BeginForm("StatsImerpts", "Administration", new { m = m }))
{
<input type="submit" value="Update" />
}
</b>
);
Has anyone tried to do this before? I know that I can use javascript and pass all the values of the row to a function but if I could just do a POST and pass the row values I think that would be simpler.