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

Combobox in beginform submitting two querystring values

1 Answer 116 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
daniel
Top achievements
Rank 1
daniel asked on 15 Sep 2015, 01:51 PM

Hi,

We have a combobox and a button inside a form (all HTML helper) and when we submit (its just a search form) two querystring items are appended to the forms destination - one with the name of the "Combobox" giving the value and one with "ComboBox_input" giving the text.

We're using a combobox so we can have the Text and the Value separate.

How can we stop both the Text AND Value being added as a querystring value?

I know we can do an on change event and window.location, but we've a requirement for an actual button to click and I thought this would work ...

01.@using (Html.BeginForm("Details", "Property", FormMethod.Get))
02.    {
03.     
04.    @(Html.Kendo().ComboBox()
05.    .Name("PropertyId")
06.    .DataTextField("Searchable")
07.    .DataValueField("PropertyRef")
08.    .Placeholder("Search for property by ref or name ...")
09.    .Filter(FilterType.Contains)
10.    .AutoBind(false)
11.    .MinLength(4)
12.    .DataSource(source =>
13.    {
14.        source.Read(read =>
15.        {
16.            read.Action("PropertySearch_Read", "Search");           
17.        })
18.    .ServerFiltering(false);
19.    })
20.   .HtmlAttributes(new { style = "width:100%" })
21.    )
22. 
23. 
24.    @(Html.Kendo().Button()
25.        .Name("btnSubmit")
26.        .HtmlAttributes(new { type = "submit" })
27.        .Content("Search")
28.    )
29.}

Thanks,

Daniel

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 17 Sep 2015, 10:31 AM
Hello Daniel,

The ComboBox widget is designed to add name attribute to the visible input element. This is required by some server frameworks (ASP.NET MVC for instance) to return the posted value when the model is not valid.

If you would like to prevent this behavior, then you can remove the name attribute from the element using JavaScript:
<!-- widget declaration -->
<script>
  $(function() {
    $("#PropertyId").data("kendoComboBox").input.removeAttr("name");
  });
</script>

Regards,
Georgi Krustev
Telerik
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
Tags
ComboBox
Asked by
daniel
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or