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

Pass data value to the grid in partial view

How do I pass a datavalue from a dropdownlist to the grid in the partial view.
I want to save a data from a grid along with the datavalue in the dropdownlist.
Thank you

9 Replies

MS Madhu Sudhanan P Syncfusion Team March 21, 2019 07:21 AM

Hi Mohd, 

Greeting from Syncfusion. 

Query: I want to save a data from a grid along with the datavalue in the dropdownlist. 
From your query, we understood that you want to apply external dropdown list value to the grid field while perform editing and adding in Grid  so we suggest you to use the  below way to achieve your requirement. 

In the below code example, we have bind the actionBegin event(checked requestType as save so it call when perform adding and updating record in Grid) and applied the dropdown list value for Grid EmployeeID field. Now the DropDown value can be accessed at the server side/controller using the property EmployeeID.  

    selector: 'app-container', 
    template: ` 
    <ejs-grid #grid [dataSource]='data' [allowPaging]='true'[allowFiltering]='true' [allowSorting]='true' [filterSettings]='filterOptions' [editSettings]='editSettings' (actionBegin)="actionBegin($event)"> 
            <e-column field='EmployeeID' headerText='EmployeeID' ></e-column> 
export class AppComponent implements OnInit { 
    actionBegin(args): void { 
        if (args.requestType === 'save') { 
               // you can assign external dropdown list value to grid field 
               args["data"]["EmployeeID"] = ddObj.value; 

If we misunderstood your query then share more information it will helpful for us to provide  a better solution as soon as possible. 

Madhu Sudhanan P  

MM Mohd Mohaimin Zakaria March 21, 2019 10:25 PM

Thanks for the reply.
I'm sorry, I'm using .NET Core Platform.
The dropdown is outside of the grid.
But when I want to save/update the data in the grid, the value of the dropdown is also saved along with the grid in one table/store procedure.
Can you provide the example based on .NET Core. Thanks.

MS Madhu Sudhanan P Syncfusion Team March 22, 2019 02:27 AM

Hi Mohd, 

Thanks for your update. 

As per your suggestion we have created a sample in ASP.NET core Platform. Please find the below code example and sample for more information. 

<div class='content'> 
    <ejs-dropdownlist id="games" dataSource="@ViewBag.DataSource" value="ViewBag.value" placeholder="Select a customer Name" popupHeight="200px"> 
        <e-dropdownlist-fields text="Email"></e-dropdownlist-fields> 
<div id="ControlRegion"> 
    <ejs-grid id="Grid" dataSource="ViewBag.DataSource" actionBegin="actionBegin" toolbar="@(new List<string>() { "Add","Edit", "Update", "Cancel" })" allowPaging="true"> 
        <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings> 
            <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column> 
            <e-grid-column field="Email" headerText="Email" width="150" type="email"></e-grid-column> 
    function actionBegin(args) { 
        if (args.requestType === 'save') { 
            // we have stored the dropdown value for grid Email field 
            args.data['Email'] = document.getElementById('games').ej2_instances[0].value; 

Madhu Sudhanan P 

MM Mohd Mohaimin Zakaria March 22, 2019 03:11 AM

Thanks for the reply.

In your example, the dropdown and the grid is in a same view.
In my situation, the dropdown is on the main view while the grid is in a partial view.
So how could the dropdown value being passed to the grid in the partial view when 'save'.


MS Madhu Sudhanan P Syncfusion Team March 22, 2019 03:50 AM

Hi Mohd, 

Thanks for the update. 

After partial view is inserted into the view page, both dropdown and grid will be in the same document tree and so you can simply access it with the solution provided previously. If we misunderstood your requirement, please share us the view page and partial view page code and also how the partial view page is inserted into the current view to analyze further on this problem.  

Madhu Sudhanan P 

MM Mohd Mohaimin Zakaria March 25, 2019 04:31 AM

Main view code

<div class="container-fluid" style="background-color:white; height:900px;">
                <div class='row'>
                    <div class="col-md-2">
                        <b>Risk Match Name</b>
                        <div class="col-md-6">
                            <ejs-dropdownlist id="cmbRiskMatch" enabled="false" placeholder="Select Risk Match Name" dataSource="@ViewBag.RiskMatchDataType"
                                              change="valueChange" ignoreAccent="true" allowFiltering="true" ejs-for="RiskMatchDesc" popupHeight="220px" width="100%">
                                <e-dropdownlist-fields text="RiskMatchDesc" value="RiskMatchDesc"></e-dropdownlist-fields>

        <div id="EQL" class="row">
            <div class="col-md-12">
                @Html.Partial("_ConfigureScore_EQL", Model)

Partial view code

    <ejs-grid id="Grid" actionBegin="actionBegin" 
              toolbar="@(new List<string>() { "Add", "Edit", "Delete","Cancel","Update","ExcelExport" })"
        <e-data-manager url="/ConfigureScore/GetScoringConfigDS" insertUrl="/ConfigureScore/AddConfigureScore" updateUrl="/ConfigureScore/UpdateConfigureScore" removeUrl="/ConfigureScore/DeleteConfigureScore" adaptor="UrlAdaptor"></e-data-manager>
        <e-grid-editSettings allowAdding="true"
        <e-grid-filterSettings type="Menu"></e-grid-filterSettings>
        <e-grid-selectionsettings type="Single"></e-grid-selectionsettings>
        <e-grid-pagesettings pageCount="5" pageSize="10" pageSizes="@(new string[] { "5", "10", "20", "All"}) "></e-grid-pagesettings>
            <e-grid-column field="ValueToMatch" headerText="First Value" validationRules="@(new { required = true })" textAlign="Left" format="C2" width="250"></e-grid-column>
            <e-grid-column field="Score" headerText="Score" validationRules="@(new { required = true })" textAlign="Left" format="C2" width="150"></e-grid-column>
            <e-grid-column field="Description" headerText="Description" validationRules="@(new { required = false })" textAlign="Left" format="C2" width="250"></e-grid-column>
            <e-grid-column field="RiskMeasureId" headerText="RiskMeasureId" validationRules="@(new { required = true })" textAlign="Left" visible="false" format="C2" width="25" defaultValue="@ViewBag.MeasureId" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="RiskMeasureEntityId" headerText="RiskMeasureEntityId" isPrimaryKey="true" validationRules="@(new { required = true })" textAlign="Left" visible="false" format="C2" width="25" defaultValue="@ViewBag.RiskMeasureEntityId" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="DocumentTypeDesc" headerText="DocumentTypeDesc" visible="false" defaultValue="@ViewBag.DocumentTypeDesc" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="RiskEntityId" headerText="RiskEntityId" visible="false" defaultValue="@ViewBag.RiskEntityId" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="RiskEntityDesc" headerText="RiskEntityDesc" visible="false" defaultValue="@ViewBag.RiskEntityDesc" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="RiskMatchDesc" headerText="RiskMatchDesc" visible="false" defaultValue="@ViewBag.RiskMatchDesc" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="RiskMatchId" headerText="RiskMatchId" visible="false" defaultValue="@ViewBag.RiskMatchId" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="SecondVaueToMatch" headerText="No" visible="false" defaultValue="@ViewBag.SecondVaueToMatch" showInColumnChooser="false"></e-grid-column>
            <e-grid-column field="GranuleCode" headerText="Granule Code" visible="false" defaultValue="@ViewBag.GranuleCode" showInColumnChooser="true"></e-grid-column>

        function actionBegin(args) {
            if (args.requestType === 'save') {
                args.data['RiskMatchDesc'] = document.getElementById('cmbRiskMatch').ej2_instances[0].value;

TS Thavasianand Sankaranarayanan Syncfusion Team March 26, 2019 04:35 AM

Hi Mohd, 

Thanks for your update. 

As per your suggestion, we have created as sample and rendered Grid in partial view & dropdown in Main View(Index.cshtml) and its working fine at our sample. Could you please find the below sample for more information. 

If you still faced the problem then provide below details it will helpful for us to validate further. 

  1. Share whether you are not able to get the dropdown value in partial view(actionBegin event) ?
  2. Did you faced any script error?
  3. If possible reproduce the reported problem with our sample.

Thavasianand S. 

MM Mohd Mohaimin Zakaria March 28, 2019 08:41 PM


Thanks for your help. Got it.

MS Madhu Sudhanan P Syncfusion Team March 28, 2019 11:56 PM

Hi Mohd, 
Thanks for the update. 

Live Chat Icon For mobile
Up arrow icon