We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid in a partial veiw

I am trying to use a grid in a partial view. Can I databind it using ViewBag like I do in a regular view? I am using an ajax call to the controller to get the data. I does get the data and assign to a ViewBag object, But the grid does not populate.

5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team May 27, 2019 02:36 AM

Hi Adam,  

Greetings from Syncfusion support.  

Query: “Grid in partialView” 

From your query we understand that you need to render the Grid using partial view. As per your requirement we have prepared a sample to render Grid in partial view on button click. Refer the below code example 

[Index.cshtml] 
 
<div id="main"> 
    @Html.EJS().Button("primarybtn").Content("Show the Grid in Partial View").IsPrimary(true).Render() 
</div> 
<div id="GridJ2" /> 
 
<script type="text/javascript"> 
    // click event to call ajac post to server 
    document.getElementById("primarybtn").addEventListener("click", function () { 
        var ajax = new ej.base.Ajax("/Home/ProductpartialEJ2/", 'POST', true); 
        ajax.send().then((data) => { 
            $("#GridJ2").html(data); 
        }); 
    }); 
</script> 

…………………….. 
[HomeController.cs] 

public ActionResult ProductpartialEJ2() 
        { 
            if(order.Count == 0) 
            BindDataSource(); 
            var model = order; 
            ViewBag.data = order;            
            return PartialView("_GridFeaturesJ2", ViewBag); 
        } 

…………………….. 

[_GridFeaturesJ2.cshtml] 

  @Html.EJS().Grid("GridJ2").DataSource((IEnumerable<object>)ViewBag.data).Columns(col => 
            { 
                col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("75").Add(); 
                col.Field("CustomerID").HeaderText("Customer ID").Width("80").Add(); 
                col.Field("OrderDate").HeaderText("Order Date").Format("yMd").Width("75").Add(); 
                col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("75").Add(); 
 
            }).AllowPaging().PageSettings(p => p.PageSize(10)).Render() 
 
    @Html.EJS().ScriptManager() 

  
For your convenience we have prepared a sample which can be downloaded from below link  


Please get back to us if you have further queries.  

Regards, 
Thavasianand S.  



AD Adam May 27, 2019 07:18 AM

Thank you for the quick response. This worked perfectly.


TS Thavasianand Sankaranarayanan Syncfusion Team May 27, 2019 09:46 PM

Hi Adam, 
 
Thanks for your update. 
 
We are happy that the problem has been resolved at your end. 
 
Regards, 
Thavasianand S.  



RV Rubén Valentín replied to Thavasianand Sankaranarayanan March 27, 2020 04:32 AM

Hi Adam, 
 
Thanks for your update. 
 
We are happy that the problem has been resolved at your end. 
 
Regards, 
Thavasianand S.  


How can i do on Razor pages?


RR Rajapandi Ravi Syncfusion Team March 31, 2020 02:49 AM

Hi Rubén, 

Thanks for the update 

Based on your query, we have prepared a sample with razor pages. We have shared the sample as given, it is bind the Dialog edit form using partial view in razor application. 

 
Regards, 
Rajapandi R 


Loader.
Live Chat Icon For mobile
Up arrow icon