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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

MVC Core Tag helpers in action template

Thread ID:

Created:

Updated:

Platform:

Replies:

144288 Apr 29,2019 08:59 AM UTC Apr 30,2019 11:54 AM UTC ASP.NET Core 1
loading
Tags: Grid
Sandhya Gademsetti
Asked On April 29, 2019 08:59 AM UTC

Hi Team,

We have a grid with custom drop down with a list of options.
Is there any way to bind these options using MVC tag helpers?

General code (Working):

<script type="text/x-template" id="actionTemplate">
    <div class="d-flex align-items-center">
        <select class="dropdown-input form-control input-box moz-form mr-3 gridActionsSelect"  id="gridActionsSelect" onchange="enableButton(this)">
            <option value="0" selected>Select</option>
            <option value="1">Future Fill Date</option>
            <option value="2">Transfer Rx</option>
            <option value="3">Resubmit Claim</option>
            <option value="4">Send to OE</option>
            <option value="5">FileOnly</option>
        </select>
        <span class="fa fa-save exceptionGridSaveIcon" style="display:none" id="" data-orderNumber="${orderNumber}" onclick="save(this)"></span>
    </div>
</script>

MVC Tag helper asp-item code (not Working):

<script type="text/x-template" id="actionTemplate">
    <div class="d-flex align-items-center">
        <select class="dropdown-input form-control input-box moz-form mr-3 gridActionsSelect" asp-items="DropDownListUtility.GetQueueItems()" id="gridActionsSelect" onchange="enableButton(this)">
          
        </select>
        <span class="fa fa-save exceptionGridSaveIcon" style="display:none" id="" data-orderNumber="${orderNumber}" onclick="save(this)"></span>
    </div>
</script>

Vignesh Natarajan [Syncfusion]
Replied On April 30, 2019 11:54 AM UTC

Hi Sandhya, 
 
Thanks for contacting Syncfusion Support. 
 
Query#:- We have a grid with custom drop down with a list of options. Is there any way to bind these options using MVC tag helpers? 
 
From your query, we understand that you need to used to MVC tag helpers inside the script tag used for column template featrue of ejGrid. But we cannot directly use tag Helpers inside the script Tag, because we cannot serialize the data and bind to Taghelpers under script Tag.  
 
To overcome this problem, we have achieved your requirement using template-refresh event of the Grid. We have placed the dropdown as Template column and rendered as ejDropdown using template-refresh event of the Grid and bind dataSourcer from server end. 
 
Refer to the  code example;- 
<ej-grid id="FlatGrid" allow-paging="true" datasource="ViewBag.datasource" allow-filtering="true" template-refresh="refresh"> 
    <e-columns> 
        <e-column header-text="Template" template="#columnTemplate" width="75" field="EmployeeID"></e-column> 
        <e-column field="OrderID" header-text="Order ID" is-primary-key="true" text-align="Right" width="75"></e-column> 
        .     .     . 
 
 
    </e-columns> 
</ej-grid> 
 
<script type="text/x-jsrender" id="columnTemplate"> 
 
    <div><input id='dropdown{{:EmployeeID}}'></div> 
</script> 
 
<script type="text/javascript"> 
    
    function refresh(args) { 
       var data = @Html.Raw(Json.Serialize(ViewBag.datasource1)) 
       $(args.cell).find("#dropdown" + args.rowData.EmployeeID).ejDropDownList({ width: 150, dataSource: data, fields: { text: "text", value: "value" } }); 
    } 
 
</script> 
 
Serverside:- 
      public ActionResult Index() 
        {             
             
            bike.Add(new Bikes { empid = "bk1", text = "Apache RTR" }); 
            bike.Add(new Bikes { empid = "bk2", text = "CBR 150-R" }); 
            bike.Add(new Bikes { empid = "bk3", text = "CBZ Xtreme" }); 
            bike.Add(new Bikes { empid = "bk4", text = "Discover" }); 
            bike.Add(new Bikes { empid = "bk5", text = "Dazzler" }); 
            ViewBag.datasource1 = bike; 
            return View(); 
        } 
 
 
Refer our API documentation for your reference 
 
 
If you are having different requirement other than above solution, please get back to us with further details. 
 
Regards, 
Vignesh Natarajan. 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon