0

有没有人设法在网格中创建表单?

尝试(不起作用):

 <%= Html.Grid(ViewData["xyz"] as IEnumerable<xyz>).Columns(column =>
   {
    column.For(gf => gf.Value).Named("Value");
    column.For(gf => 
     <% using (Html.BeginForm("deletebla", "controllername", FormMethod.Post, new { @class = "deleteForm" })) 
{ %>  
<input type="submit" value="Delete" /> 
 <% } 
 %>  
).Named("");
 }).Empty("Sorry no data.")%>

谢谢。

克里斯

4

1 回答 1

1

这里有两种可能性(在我的示例中,我将使用强类型视图而不是ViewData为了促进良好的实践)。

使用动作语法

<% 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();
%>

在 web.config 中添加它以确保适当的扩展方法在范围内之后:

<system.web>
  <pages>
    <namespaces>
        <add namespace="MvcContrib.UI.Grid.ActionSyntax" />
    </namespaces>
  </pages>
</system.web>

或者,如果您想避免标签汤,只需使用部分:

<%= Html.Grid<UserViewModel>(Model)
    .Columns(column =>
    {
        column.For("Test").Named("Value").Partial("Foo");
    })
%>

并在Foo.ascx

<% using (Html.BeginForm("deletebla", "controllername", FormMethod.Post, new { @class = "deleteForm" })) { %>

<% } %>

我肯定会选择第二个选项。

于 2010-07-12T16:29:52.613 回答