Html.X().ComboBoxFor bug

  1. #1

    Html.X().ComboBoxFor bug

    Hi,
    I write new thread for specify subject.

    There is a bug about Html.X().ComboBoxFor(). As you see attachment Form data is normal. But Posted data Combobox is null. Problem is about model property is type of Ext.Net.ListItem or Ienumarable<Ext.Net.ListItem>

    Thanks

    Click image for larger version. 

Name:	Bugs_Model_Bind.png 
Views:	45 
Size:	44.8 KB 
ID:	5903
  2. #2
    Hello!

    Thank you for your report. Can you provide example to reproduce?

    http://forums.ext.net/showthread.php?10205
  3. #3
    Quote Originally Posted by Baidaly View Post
    Hello!

    Thank you for your report. Can you provide example to reproduce?

    http://forums.ext.net/showthread.php?10205
    I just add a submit button to your demo code ( http://mvc.ext.net/#/Models/Model_Bind/ ) to see post result.

    ..................................Controller...... .....................................
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace Ext.Net.MVC.Examples.Areas.Models.Controllers
    {
        public class Model_BindController : Controller
        {
            public ActionResult Index()
            {
                return View(new Model_BindModel { 
                    TextValue = "TextValue",
                    DateTimeValue = DateTime.Now,
                    ComboValue1 = new ListItem("Item 3", "3"),
                    ComboValue2 = new ListItem[] { 
                        new ListItem("Item 1", "1"), 
                        new ListItem("Item 5", "5") 
                    },
                    ComboValue3 = "2",
                    CheckboxValue = true,
                    NumberValue = 1,
                    MultiSliderValue = new int[] { 10, 40, 70 },
    
                    Data = new ListItem[] { 
                        new ListItem("Item 1", "1"), 
                        new ListItem("Item 2", "2"),
                        new ListItem("Item 3", "3"),
                        new ListItem("Item 4", "4"),
                        new ListItem("Item 5", "5")
                    }
                });
            }
    
            public ActionResult DirectEventSubmit(Model_BindModel ModelBind)
            {
                X.Msg.Alert("Submit", JSON.Serialize(ModelBind)).Show();
                return this.Direct();
            }
        }
    }
    ............................ View.......................................
    @model Ext.Net.MVC.Examples.Areas.Models.Model_BindModel
    @{
        ViewBag.Title = "Model Bind";
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
    }
    
    @section example
    {
        <h1>Model Bind</h1>
    
        @(
            Html.X().FormPanel()
            .Layout(LayoutType.Form)
            .Width(350)
            .FieldDefaults(d => {
                d.LabelWidth = 150;
            })
            .ID("FormPanel1")
            .BodyPadding(10)
            .Frame(true)
            .Items(
                Html.X().TextFieldFor(m => m.TextValue),
                Html.X().DateFieldFor(m => m.DateTimeValue),
                Html.X().ComboBoxFor(m => m.ComboValue1).Items(Model.Data),
                Html.X().ComboBoxFor(m => m.ComboValue2).Items(Model.Data),
                Html.X().ComboBoxFor(m => m.ComboValue3).Items(Model.Data),
                Html.X().CheckboxFor(m => m.CheckboxValue),
                Html.X().NumberFieldFor(m => m.NumberValue),
                Html.X().SliderFor(m => m.MultiSliderValue)   
            )
             .Buttons(
                    Html.X().Button()
                        .Text("Submit variations")
                        .MenuItem(
                            Html.X().MenuItem()
                                .Text("DirectEvent submit")
                                .DirectEvents(de => {
                                    de.Click.Url = Url.Action("DirectEventSubmit");
                                    de.Click.EventMask.ShowMask = true;
                                    de.Click.FormID = "FormPanel1";
                                })
                        )
                )
        )    
    }
    .................................................. ............Model................................. .............
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Web.Mvc;
    using Ext.Net;
    
    namespace Ext.Net.MVC.Examples.Areas.Models
    {
        public class Model_BindModel
        {
            [Field(FieldLabel="TextField")]
            public string TextValue
            {
                get;
                set;
            }
    
            [Field(FieldLabel = "DateField")]
            public DateTime DateTimeValue
            {
                get;
                set;
            }
    
            [Field(FieldLabel = "ComboBox 1")]
            public ListItem ComboValue1
            {
                get;
                set;
            }
    
            [Field(FieldLabel = "ComboBox 2")]
            public IEnumerable<ListItem> ComboValue2
            {
                get;
                set;
            }
    
            [Field(FieldLabel = "ComboBox 3")]
            public string ComboValue3
            {
                get;
                set;
            }
    
            [Field(FieldLabel = "CheckBox")]
            public bool CheckboxValue
            {
                get;
                set;
            }
    
            [Field(FieldLabel = "NumberField")]
            public int NumberValue
            {
                get;
                set;
            }
    
            [Field(FieldLabel = "MultiSlider")]
            public int[] MultiSliderValue
            {
                get;
                set;
            }
    
            public IEnumerable<ListItem> Data
            {
                get;
                set;
            }
        }
    }
    Last edited by Baidaly; Mar 26, 2013 at 9:22 PM. Reason: Please, use the [CODE] tag
  4. #4
    This is default behavior of ASP.NET MVC ModelBinder with Complex type and Enumerable. To access ComboBox values you should use the following approach:

    public ActionResult DirectEventSubmit(string ComboValue1, string ComboValue2, string ComboValue3)
    {
    	return this.Direct();
    }
    Thread was moved to 2.x Help forum.
    Last edited by Baidaly; Mar 26, 2013 at 11:34 PM.

Similar Threads

  1. ComboBoxFor and empty value after load
    By zwf in forum 2.x Help
    Replies: 1
    Last Post: Nov 12, 2012, 1:46 PM
  2. Replies: 3
    Last Post: Nov 05, 2012, 11:51 AM
  3. Replies: 9
    Last Post: Oct 08, 2012, 7:49 AM
  4. Replies: 2
    Last Post: Nov 03, 2011, 5:24 PM
  5. Replies: 1
    Last Post: May 28, 2010, 1:13 PM

Posting Permissions