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

MVC Core Tag helpers in action template

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>

1 Reply

VN Vignesh Natarajan Syncfusion Team 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. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon