AutoComplete Data-Bind html attributes

2 posts, 0 answers
  1. Gregor
    Gregor avatar
    17 posts
    Member since:
    May 2012

    Posted 14 Sep 2012 Link to this post

    Id like to extend to the AutoComplete helper to pass in a data-bding html 5 attribute, I have the following:-

    @(Html.Kendo().AutoComplete()
              .Name("productAutoComplete")
              .DataTextField("id")
              .DataTextField("name")
              .DataSource(source =>
                  {
                      source.Read(read =>
                          {
                              read.Action("ProductSuggestions", "Search")
                                .Data("onAdditionalData").Type(HttpVerbs.Get);
                          }).ServerFiltering(true);
                  })
                  .Enable(true)
        )

    I want to be able to add a new HtmlAttrobute something like this:-

    .HtmlAttributes(new[] { "data-bind='executeOnEnter: products'" })

    So that I can use a knockoutJS custom binding - can anyone help me with this?
  2. kashyapa
    kashyapa avatar
    7 posts
    Member since:
    Jan 2011

    Posted 16 Oct 2012 Link to this post

    Here's what you need to do to achieve that :

    @(Html.Kendo().AutoCompleteFor(model => model.Person.State.Abbreviation)
                         .BindTo(Model.States)
                         .DataTextField("Abbreviation")
                         .HtmlAttributes(new { data_bind="executeOnEnter:products" })
            )

  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top