Add MultiSelect Values that are not in the bound list

2 posts, 1 answers
  1. Bartley
    Bartley avatar
    16 posts
    Member since:
    Mar 2013

    Posted 13 Nov 2013 Link to this post

    I am populating The auto-complete portion of the Multi-Select like below

    Controller:
    public JsonResult lstNames(string name)
    {
        var lstOfNames = db.GetNames.Select(e => new
        {
            name = e.Names
        });
        return Json(lstOfNames , JsonRequestBehavior.AllowGet);
    }

    Razor:

    @(Html.Kendo()
          .MultiSelect()
          .Name("names")
          .AutoBind(true)
          .Placeholder("Select names...")
          .DataTextField("name")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("lstNames", "ListNamesView");
              })
                    .ServerFiltering(true);
          })
     
    )

    I was wondering is it possible to bind the value to a list that is not in the auto-complete list and also be able to type a new name in as the value?


  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 15 Nov 2013 Link to this post

    Hello Bartley,

    You cannot enter any free text, however you can add/insert new items to the dataSource that the multiselect uses and thus they will become part of the collection as the other initial items.

    e.g.

    http://jsbin.com/uWEvulEn/2/edit

    You can also set the value programatically with the value method.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top