- Home
- Forum
- ASP.NET Core - EJ 2
- Default value for Autocomplete
Default value for Autocomplete
|
<ejs-autocomplete id="country" dataSource="@ViewBag.data" value="@ViewBag.value" placeholder="e.g. india" popupheight="220px" itemTemplate="@Html.Raw("<span><span class='name'>${Name}</span><span class ='code'>${Code}</span></span>")">
<e-autocomplete-fields value="Name"></e-autocomplete-fields>
</ejs-autocomplete>
|
|
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.data = new Countries().CountriesList();
ViewBag.value = "Bermuda";
return View();
}
}
|
Hi Koen,Greetings from Syncfusion support.We have validated you reported query. Autocomplete component supports value field alone. We have prepared sample for set default value to autocomplete component. Please find the code snippet and test sample below for reference.[Index.cshtml]
<ejs-autocomplete id="country" dataSource="@ViewBag.data" value="@ViewBag.value" placeholder="e.g. india" popupheight="220px" itemTemplate="@Html.Raw("<span><span class='name'>${Name}</span><span class ='code'>${Code}</span></span>")"><e-autocomplete-fields value="Name"></e-autocomplete-fields></ejs-autocomplete>[HomeController.cs]
public class HomeController : Controller{public IActionResult Index(){ViewBag.data = new Countries().CountriesList();ViewBag.value = "Bermuda";return View();}}Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/EJ2_Core_Autocomplet_defultvalue158581111Regards,Ponmani M
Dear,
you say "Autocomplete component supports value field alone", however the examples at https://ej2.syncfusion.com/aspnetcore/documentation/auto-complete/data-binding/?no-cache=1#array-of-complex-object show both value and text fields...?
secondly, you propose to set the default value with "value="@ViewBag.value" " . Is it not possible to set it with "value="BE" " ?
Thanks,
Koen
|
<ejs-autocomplete id="country" dataSource="@ViewBag.data" placeholder="e.g. india" popupheight="220px" created="onCreate" itemTemplate="@Html.Raw("<span><span class='name'>${Name}</span><span class ='code'>${Code}</span></span>")">
<e-autocomplete-fields value="Name"></e-autocomplete-fields>
</ejs-autocomplete>
<script>
function onCreate() {
this.value = "Bermuda"
}
</script> |
Sample Link : https://www.syncfusion.com/downloads/support/forum/153124/ze/EJ2_Core_Autocomplet_defultvalue728389381
Regards,
I am concerned about this product since this post was submitted over a year ago and stated the documentation would be updated. I find the documentation is still out of date and for the auto complete field it still shows it can accept a text attribute.
In addition, I have found that using a ViewBag doesn't work in my case. Possibly because I am using an item template with two columns of data.
The option to set it in the OnCreate is not something I prefer to utilize since I'm setting all my defaults in the controller and am basing it on calculations. While I realize the foundation of the product is largely javascript, it does still need to support code behind options.
I am posting this in the hopes that this matter will be reviewed, the documentation updated, and a solution that supports asp .net core is made available to us i.e. not using javascript on the form.
- Simple sample which reproduces the issue.
- Video demonstration which reproduces the issue.
Data-Binding : https://ej2.syncfusion.com/aspnetcore/documentation/auto-complete/data-binding/
|
<ejs-autocomplete id="employees" dataSource="@ViewBag.data" value="@ViewBag.Value" placeholder="e.g. Andrew Fuller" popupHeight="450px"
headerTemplate="@Html.Raw("<div class=\"header\"> <span class=\"info\">Employee Name</span><span class=\"info\">Designation</span> </div>)")"
itemTemplate="@Html.Raw("<div><divclass=\"ename\"> ${FirstName} - ${Designation}</div></div>")"> <e-autocomplete-fields value="FirstName"></e-autocomplete-fields>
</ejs-autocomplete> |
- 5 Replies
- 5 Participants
-
KO Koen
- Apr 8, 2020 08:42 AM UTC
- Jul 26, 2021 11:54 AM UTC