This is a migrated thread and some comments may be shown as answers.

Local binding with tag helper

1 Answer 878 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 02 Feb 2018, 03:32 PM

Does anyone have an example for the kendoDropdownList that uses the MVC Core tag helper, and uses local binding?  The tag helper sample in the demos binds to remote data only.  Thanks!

 

1 Answer, 1 is accepted

Sort by
2
Accepted
Dimitar
Telerik team
answered on 06 Feb 2018, 02:28 PM
Hello Michael,

I am attaching an ASP.NET Core solution, where a similar scenario to the one described is demonstrated (Bind DropDownList to local data).

To achieve the desired result, the bind-to attribute is used to bind the DropDownList to a list of SelectListItem:
<kendo-dropdownlist name="orders"
   datatextfield="Text"
   datavaluefield="Value"
   filter="FilterType.Contains"
   bind-to="Model.Countries">
</kendo-dropdownlist>

The Index method initializes the HomeViewModel, sets the list of countries and passes it to the Index view:
public IActionResult Index()
{
  var homeData = new HomeViewModel()
  {
    Countries = GetCountries()
  };
 
  return View(homeData);
}
 
public IList<SelectListItem> GetCountries()
{
  var countries = new List<SelectListItem>
  {
    new SelectListItem { Value = "MX", Text = "Mexico" },
    new SelectListItem { Value = "CA", Text = "Canada" },
    new SelectListItem { Value = "US", Text = "USA"  }
  };
 
  return countries;
}


Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DropDownList
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or