This is a migrated thread and some comments may be shown as answers.

Using Html.BeginForm in a Grid Template in MVC

1 Answer 666 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 2
Ian asked on 16 Jul 2013, 09:21 PM
I have the following Razor code in a Template from a Column. The div inside the form renders fine, but strangely the <form> tags from the Html.BeginForm do not get rendered.

(I need a separate form in each of the cells)
columns.Bound(e => e.DisplayText).Title("ACTION").Template(
        @<text>
             @if (item.UserClient.IsActionAvailable())
                      {

         using (Html.BeginForm("Subscribe", "eServices", FormMethod.Post, new {id = @formId}))
       {
              <div id="@divId" class="subForm">
                 <input type="hidden" name="User" value="@clientId" />
             </div>
         }

1 Answer, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 18 Jul 2013, 08:35 AM
Hello Ian,

Two important things you need to cover:
  1. You need to use Server Binding - otherwise Template method has no effect - you should use ClientTemplate for Ajax Binding
  2. You should call the render method instead of using @() Razor operator. Using the latter will render the form elements before the Grid in the final HTML markup.

Here is an example of code that works on my side:

@model IEnumerable<KendoMVCWrappers.Models.Person>
 
@{Html.Kendo().Grid<KendoMVCWrappers.Models.Person>(Model).Name("people")
    .Columns(columns =>
    {
        columns.Bound(c => c.Name).Template(@<text>
         
         @using (Html.BeginForm("Subscribe", "eServices", FormMethod.Post, new { id = item.Name }))
         {
              <div id="id" class="subForm">
                 <input type="hidden" name="User" value="@item.Name" />
             </div>
         }
        </text>);
    })
    .Render();
    }



Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Ian
Top achievements
Rank 2
Answers by
Petur Subev
Telerik team
Share this question
or