Using Unobtrusive Ajax Forms
Let's use the MVC support for Ajax to add support for posting forms for updates. Listing 30-6 shows the changes to the Index.cshtml
view to enable this feature.
Listing 30-6. Using Ajax forms
@model string
@{
ViewBag.Title = Model + " Report";
AjaxOptions ajaxOpts = new AjaxOptions {
UpdateTargetId = "datatable"
};
}
<h2>@Model</h2>
@using (Ajax.BeginForm("RegistrationTable", ajaxOpts)) {
@Html.DropDownList("competition", new SelectList(ViewBag.CompetitionNames, Model))
<input type="submit" value="Show Report" />
}
<p />
@Html.Action("RegistrationTable", new { competition = Model })
We have to make two changes to enable Ajax forms. The first is to define an AjaxOptions
object, which ...
Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.