Two possibilities here (in my example I will be using a strongly typed view instead of ViewData
in order to promote good practice).
Use the Action Syntax:
<% Html.Grid<UserViewModel>(Model)
.Columns(column =>
{
column.For("Test").Named("Value").Action(p => { %>
<td>
<% using (Html.BeginForm("deletebla", "controllername", FormMethod.Post, new { @class = "deleteForm" })) { %>
<% } %>
</td>
<% });
}).Render();
%>
after adding this in web.config to make sure that proper extension methods are in scope:
<system.web>
<pages>
<namespaces>
<add namespace="MvcContrib.UI.Grid.ActionSyntax" />
</namespaces>
</pages>
</system.web>
Or if you want to avoid the tag soup simply use a partial:
<%= Html.Grid<UserViewModel>(Model)
.Columns(column =>
{
column.For("Test").Named("Value").Partial("Foo");
})
%>
And in Foo.ascx
:
<% using (Html.BeginForm("deletebla", "controllername", FormMethod.Post, new { @class = "deleteForm" })) { %>
<% } %>
I would definitely choose the second option.