Populating Dropdown Lists When Editing

2 posts, 0 answers
  1. Michael
    Michael avatar
    13 posts
    Member since:
    Sep 2014

    Posted 30 Aug Link to this post

    I'm trying to figure out how to populate a dropdown list when editing a ListView item. I'm binding to a ViewModel that contains an IEnumerable<SelectListItem>. On other pages without a ListView, I do something like below, however I'm not sure what action I can use to set up the model so that I have access to it when editing using the ListView.  I tried looping through each item in the Read action and setting States there, which is definitely inefficient, but regardless didn't work.  Any ideas?

    public IActionResult Index()
        var model = _service.FindById(1));
        model.States = (_lookupService.GetStates());
        return View(model);

    <select asp-for="StateId" asp-items="Model.States" class="form-control">
        <option value=""></option>
  2. Vasil
    Vasil avatar
    1541 posts

    Posted 01 Sep Link to this post

    Hello Michael,

    Have you created editor template that to be used for editing? If this is the case you can save the data into the ViewData and then use it for biding.

    @(Html.Kendo().DropDownListFor(p=> p.States)

    public ActionResult Index()
        ViewData["states"] = _lookupService.GetStates();
        return View();

    Please also check these forums, where you can find more information and working sample:

    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET AJAX banner
Back to Top