Regards,@Html.EJ().Autocomplete("selectCar").Datasource(dataSource => dataSource.URL(Url.Action("DataSource", "Autocomplete")).Adaptor(AdaptorType.UrlAdaptor)).Query("ej.Query()").AutocompleteFields(af => af.Text("text")).Width("300").FilterType(FilterOperatorType.Contains)
In the controller I have the following method:
public JsonResult DataSource() {
But I would like to use the parameterized controller method as follows:
IEnumerable Data = setListSource(); return Json(Data, JsonRequestBehavior.AllowGet); }public JsonResult DataSource(int categoryId) {
IEnumerable Data = setListSource(
categoryId
); return Json(Data, JsonRequestBehavior.AllowGet);
}How do I configure the view autocomplete datasource with the controller parameter?
View:
@Html.EJ().Autocomplete("selectCar").Query("ej.Query()").ClientSideEvents(ce => ce.Change("onchange")).AutocompleteFields(af => af.Text("text")).Width("300").FilterType(FilterOperatorType.Contains)
<script>
function onchange(e) {
searchTerm = $('#selectCar').val();
$.ajax({
type: 'POST',
url: '@Url.Action("DataSource", "Autocomplete")',
data: {
categoryId: parseInt(searchTerm)
},
success: function (response) {
var ac = $("#selectCar").ejAutocomplete("instance");
if (response != null && response.length) {
ac.suggestionListItems = response;
ac._doneRemaining();
} else
ac._hideResult();
}
});
}
</script>
Controller:
public JsonResult DataSource(int categoryId)
{
if (categoryId == null)
{
return null;
}
else
{
IEnumerable Data = setListSource();
// Filtering based on the searched word i.e int category can be used to filter here
return Json(Data, JsonRequestBehavior.AllowGet);
}
} |
Ok Arun!
Thank you very much!
Regards,
Junior
<div class="control">
<div class="control-section">
<div class="col-lg-3 content-wrapper">
<label>AutoComplete</label>
<iput id="autocomplete" type="text" />
</div>
</div>
</div>
<script>
var atcObj1 = new ej.dropdowns.AutoComplete({
// bind the DataManager instance to dataSource property
dataSource: new ej.data.DataManager({ url: '/Home/UrlDatasource', adaptor: new ej.data.UrlAdaptor(), crossDomain: true }),
// set the placeholder to AutoComplete input element
placeholder: 'Select customer',
// set the filterType to searching operation
filterType: 'StartsWith',
});
atcObj1.appendTo('#autocomplete');
</script> |
public object UrlDatasource(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.ToLower().StartsWith(dm.@where[0].value.ToString())
select cust).ToList();
}
if (dm.take != 0)
Data = Data.Take(dm.take).ToList();
return Json(Data);
} |
|