Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,54 @@
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E4063)
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
<!-- default badges end -->
<!-- default file list -->
*Files to look at*:

* [HomeController.cs](./CS/AjaxSupport/Controllers/HomeController.cs) (VB: [HomeController.vb](./VB/AjaxSupport/Controllers/HomeController.vb))
* [GridViewPartial.cshtml](./CS/AjaxSupport/Views/Home/GridViewPartial.cshtml)
* **[Index.cshtml](./CS/AjaxSupport/Views/Home/Index.cshtml)**
<!-- default file list end -->
# How to use the jQuery.ajax function with DevExpress MVC Extensions
# Grid View for MVC - How to Use the jQuery.ajax Function with DevExpress MVC Extensions

<!-- run online -->
**[[Run Online]](https://codecentral.devexpress.com/e4063/)**
<!-- run online end -->


<p>This example demonstrates how you can use the <strong>jQuery.ajax</strong> function to load a GridView on a callback.<br />
Note that this feature has been implemented in the 12.1 version, so it is not available in earlier versions. For older versions, you can use a solution demonstrated in the <a href="https://www.devexpress.com/Support/Center/p/E2927">How to load MVC extensions using the CallbackPanel extension</a> example.</p>
This example demonstrates how to use the [jQuery.ajax](https://api.jquery.com/jquery.ajax/) function to load a GridView on a callback.

![A sample grid](images/grid-created-on-callback.png)

In this example, the grid is created when a user clicks the button on the page. Use the [ButtonSettings.ClientSideEvents](https://docs.devexpress.com/AspNetMvc/DevExpress.Web.Mvc.ButtonSettings.ClientSideEvents) property to handle button click events:

```cshtml
<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()
```

**Note:** The *jQuery.ajax* function has been supported in v.12.1. For earlier versions, you can use a solution demonstrated in the following example: [How to load MVC extensions using the CallbackPanel extension](https://github.com/DevExpress-Examples/how-to-load-mvc-extensions-using-the-callbackpanel-extension-e2927).

## Files to Look At

* [Index.cshtml](./CS/AjaxSupport/Views/Home/Index.cshtml)
* [HomeController.cs](./CS/AjaxSupport/Controllers/HomeController.cs) (VB: [HomeController.vb](./VB/AjaxSupport/Controllers/HomeController.vb))
* [GridViewPartial.cshtml](./CS/AjaxSupport/Views/Home/GridViewPartial.cshtml)

## Documentation

<br/>
* [GridViewExtension](https://docs.devexpress.com/AspNetMvc/DevExpress.Web.Mvc.GridViewExtension)
* [ButtonSettings.ClientSideEvents](https://docs.devexpress.com/AspNetMvc/DevExpress.Web.Mvc.ButtonSettings.ClientSideEvents)

## More Examples

* [How to use the GridView extension in Full Screen mode (100% browser Width and Height)](https://github.com/DevExpress-Examples/how-to-use-the-gridview-extension-in-a-full-screen-mode-100-browser-width-and-height-e3958)
* [GridView - How to edit in memory data source](https://github.com/DevExpress-Examples/gridview-how-to-edit-in-memory-data-source-e3983)
* [How to bind GridView to XPO in Server Mode](https://github.com/DevExpress-Examples/how-to-bind-gridview-to-xpo-in-server-mode-e2836)
Binary file added images/grid-created-on-callback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.