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

How to set the dataSource with urlAdaptor?

Hi, I want to make a DropDownList with the dataSource from UrlAdaptor. I start using JS2, and I do not know if it is configured the same as JS1
I have my code here:

@(Html.EJS().DropDownList("Album")
        .DataSource(ds=>
        {
            ds.Url("/JS2/Albums").Adaptor("UrlAdaptor");
        })
        .Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings
        {
            Text="Titulo", Value="AlbumId"
        })
        .Placeholder("Hola")
        .PopupHeight("200px")
        .Render()
        )

public ActionResult Albums()
        {
            var result = read.GetAlbums();
            var count = result.Count;

            return Json(new { result = result, count = count }, JsonRequestBehavior.AllowGet);
        }

I have two other questions
a) When configuring JS2 and adding the namespaces of Syncfusion.EJ2 in web.config (following the instructions in the documentation), when I try to use a control I can because I get a message saying that I am missing a reference and I always have to put at the start of my .cshtml @using Syncfusion.EJ2
Why is this happening?

b)If in my MVC project I have areas, how can I be able to in ds.Url ("/ JS2 / Albums") to add an area? Or is it not necessary to add the area?
Thanks in advance

1 Reply

CI Christopher Issac Sunder K Syncfusion Team March 4, 2019 09:14 AM UTC

Hi Juan, 

Thank you for contacting Syncfusion support. 

We already have documentation for datasource with url Adaptor. Please refer the below code snippet and the documentation, 
code snippet
[.cshtml] 
<div id='url-data' class='col-lg-6' style='padding-top:15px'>  
    <div class='content'>  
    @Html.EJS().DropDownList("games").Placeholder("Select a Country").PopupHeight("200px").DataSource(dataManger => dataManger.Url("/DropDownList/UrlDatasource").Adaptor("UrlAdaptor").CrossDomain(true)).Fields(new ComboBoxFieldSettings { Value = "ShipCountry" }).Render()  
    </div>  
</div> 

[.cs] 
public IActionResult UrlDatasource([FromBody]Data dm) 
{ 
    var val = OrdersDetails.GetAllRecords(); 
    var Data = val.ToList(); 
    var count = val.Count(); 
    if (dm.where != null) { 
        Data = (from cust in Data 
        where cust.ShipCountry.ToLower().StartsWith(dm.@where[0].value.ToString()) 
        select cust).ToList(); 
    } 
    if (dm.take != 0) 
        Data = Data.Take(dm.take).ToList(); 
    return Json(Data); 
} 


Regarding ej2 sample configuration. Please refer to the below documentation, 

Please let us know if you require any further assistance. 

Thanks, 
Christo 


Loader.
Live Chat Icon For mobile
Up arrow icon