How to bind Id of selected value back to the controller?

2 posts, 0 answers
  1. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 15 Mar 2013 Link to this post

    Maybe I'm going about this the wrong way but the model populating the AutoComplete has an Id and a Name.  I display the Name but when the form is submitted I need to return the Id since it will bind to the property on the model.

    Presently the AutoComplete is populated correctly when I start entering data, but when I submit the form, the widget has the red border meaning that it's not returning the int property type but the string type.

    These are two of the AutoComplete properties on my model that I need to bind to:
    [DisplayName("Vendor")]
    public int? VendorId { get; set; }
     
    [DisplayName("Category")]
    public int CategoryId { get; set; }
    Here is my Vendor AutoComplete widget:
    @(Html.Kendo().AutoComplete().Name("Expense.VendorId")
        .DataTextField("VendorName")
        .Filter(FilterType.StartsWith)
        .Placeholder("Type in a Vendor...")
        .DataSource(dataSource =>
        {
            dataSource.Read(read => read.Action("_GetVendors", "Expense"));
        })
        )
    Bottom line: I need to bind the Id of the selected value back to the controller, so I need to know how to return the Id from the AutoComplete widget and include it with the response.

    Any help on this is appreciated.

    Thanks.
  2. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 15 Mar 2013 Link to this post

    Nevermind.  I read one of the posts in the Web Forum with the same issue and it suggested to use the ComboBox instead.

    It now does what I need.
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top