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

[Solved] Combobox not posting back guid values.

2 Answers 189 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MGrassman
Top achievements
Rank 2
MGrassman asked on 18 Sep 2010, 05:38 AM
I have the following view where the MarketId is a Guid.  When I look at the source of the html the dropdown is rendered correctly but when I hit submit the marketid is not being passed.  I also have a textbox on the page and that passes back the data just fine.

Any suggestions?

Here is my ViewData where Zone is actually getting passed back to my Service and the rest of the objects are just to fill the Comboboxes.

ViewData
public class ZonesViewData : BaseViewData
    {
        public List<Market> Markets { get; set; }
        public List<Zone> PossibleParentZones { get; set; }
        public List<Zone> Zones { get; set; }
        public Zone Zone { get; set; }
    }


View
<% Html.EnableClientValidation(); %>
        <% using (Html.BeginForm()) {%>
         
        <%: Html.ValidationSummary(true) %>
        <div class="editor-label">
        <%: Html.LabelFor(model => model.Zone.MarketId) %>
        </div>
        <div class="editor-field">
        <%: Html.Telerik().ComboBoxFor(model => model.Zone.MarketId)
            .Name("cmbMarketId")  
            .BindTo(new SelectList(Model.Markets, "MarketId", "Name"))
            .HtmlAttributes(new {
                style = string.Format("width:200px")
            })
             
        %>
 
<p><input type="submit" value="Create" /></p>
        <% } %>

2 Answers, 1 is accepted

Sort by
0
MGrassman
Top achievements
Rank 2
answered on 18 Sep 2010, 09:33 PM
Ok well the data is coming through the request object just not binding to my model.

This works to get the correct selected value.  Any reasons why my code isn't binding to the model?

if (!String.IsNullOrWhiteSpace(Request["cmbMarketId"])) 
{    
     Guid cmbMarketId = new Guid(Request["cmbMarketId"].ToString();
     model.Zone.MarketId = cmbMarketId;
}


0
Accepted
Georgi Krustev
Telerik team
answered on 20 Sep 2010, 07:41 AM
Hello MGrassman,

After further review of the code snippet, which shows how ComboBox component is declared, I have noticed that you are using ComboBoxFor extension and then set the Name of the component. Thus the value, which will be send to the server will be available in the Request.Form under "cmbMarketId" key. This is expected. ValueProvider will try to populate "item.Zone.MarketId" (item is a param in the Action method), and will look for value with "Zone.MarketId" key. In other words if you are using ComboBoxFor extensions do not use Name method to override already set name of the component.

All the best,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
MGrassman
Top achievements
Rank 2
Answers by
MGrassman
Top achievements
Rank 2
Georgi Krustev
Telerik team
Share this question
or