Example E4063
Visible to All Users

Grid View for APS.NET MVC - How to use the jQuery.ajax function with DevExpress MVC extensions

This example demonstrates how to use the jQuery.ajax function to load the GridView extension on a callback.

A sample grid

In this example, we handle a button's Click event to call the $.ajax() function. The function sends an AJAX (asynchronous HTTP) request to the GridViewPartial action and renders the action result (GridViewPartial.cshtml) to the div container.

Razor
<script type="text/javascript"> function OnClick(s, e) { $.ajax({ type: "POST", url: "@Url.Action("GridViewPartial")", success: function(response) { $("#container").html(response); } }); } </script> @Html.DevExpress().Button(settings => { settings.Name = "MyButton"; settings.Text = "Click Me!!!"; settings.ClientSideEvents.Click = "OnClick"; }).GetHtml()

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

AjaxSupport/Views/Home/GridViewPartial.cshtml
Razor
@Html.DevExpress().GridView(settings => { settings.Name = "gridView"; settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" }; }).Bind(Model).GetHtml()
AjaxSupport/Views/Home/Index.cshtml
Razor
<script type="text/javascript"> function OnClick(s, e) { $.ajax({ type: "POST", url: "@Url.Action("GridViewPartial")", success: function(response) { $("#container").html(response); } }); } </script> @Html.DevExpress().Button(settings => { settings.Name = "MyButton"; settings.Text = "Click Me!!!"; settings.ClientSideEvents.Click = "OnClick"; }).GetHtml() <div id="container" class="container"> </div>
AjaxSupport/Views/Home/Index.vbhtml
Code
<script type="text/javascript"> function OnClick(s, e) { $.ajax({ type: "POST", url: "/Home/GridViewPartial", success: function(response) { $("#container").html(response); } }); } </script> @Html.DevExpress().Button(Sub(settings) settings.Name = "MyButton" settings.Text = "Click Me!!!" settings.ClientSideEvents.Click = "OnClick" End Sub).GetHtml() <div id="container" class="container"> </div>
AjaxSupport/Controllers/HomeController.cs(vb)
C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using AjaxSupport.Models; namespace AjaxSupport.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult GridViewPartial() { return PartialView("GridViewPartial", InMemoryModel.GetDataTableModel()); } } }
AjaxSupport/Views/Home/GridViewPartial.vbhtml
Code
@Html.DevExpress().GridView( Sub(settings) settings.Name = "gridView" settings.CallbackRouteValues = New With { Key .Controller = "Home", Key .Action = "GridViewPartial" } End Sub).Bind(Model).GetHtml()

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.