[CLOSED] MVC FormPanelForModel boolean submit behaviour

  1. #1

    [CLOSED] MVC FormPanelForModel boolean submit behaviour

    Hi,

    I've seen that FormPanelForModel for boolean fields, posts as value the created CheckBox's id, instead of simply true, when no instance of model is passed to the view. This causes an invalid ModelState because of wrong AttemtedValue.

    For example:

    let's assume we have a simple login model
    public class LogOnModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }
    
        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }
    
        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }
    }
    a simple login view
    @model Models.LogOnModel
    @{
        ViewBag.Title = "Login";
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
    }
    
    @(
        Html.X().FormPanelForModel()
            .Buttons( Html.X().Button().Text("Submit")
                .DirectClickUrl(Url.Action("Submit")) ) 
                //You can use a direct event and bind the form.
                //You will get the same result.
     )
    and a login controller
    public ActionResult Index()
    {
        return View(); //no instance of model is given to the view
    }
    
    [HttpPost]
    public ActionResult Submit(Models.LogOnModel test)
    {
        if (Model.IsValid)
        {
            //Your login ticket and redirection return code should be here. 
            //You may can put a breakpoint before this if statement to check the ModelState.Values to see the AttemtedValue
        }
        return this.Direct();
    }

    Http Post of this form (if RememberMe field is checked) can be monitored in Firebug like this:
    application/x-www-form-urlencoded
    Parameters
    Password asdf
    RememberMe App.RememberMe
    UserName asdf
    Source
    UserName=asdf&Password=asdf&RememberMe=App.Remembe rMe

    As you see App.RememberMe value for boolean field will cause a false Model.IsValid


    Walk-around of this issue can be one of these:
    • giving an empty instance of the model to the view
      public ActionResult Index()
      {
          return View(new Models.LogOnModel());
      }
    • or declaring the InputValue of boolean fields manually
      @model Models.LogOnModel
      @(
          Html.X().FormPanelForModel(modelOnly:true)
              .Items(
                Html.X().TextFieldFor(m=>m.UserName),
                Html.X().TextFieldFor(m=>m.Password),
                Html.X().CheckboxFor(m=>m.RememberMe).InputValue("true").UncheckedValue("false"))
              .Buttons( Html.X().Button().Text("Submit")
                  .DirectClickUrl(Url.Action("Submit")) ) 
       )



    In both of these solutions you will get a true or false value on the http post, which will produce a valid ModelState.

    My question is:
    Is this behavior of Ext.Net.Model or FormPanelForModel classes a bug to solve, or is it a feature "as is" we need to walk-around?

    You can reproduce this issue easily on the FormPanelFor example, just by removing FormPanelEmployee.GetAll()[0] parameter on the controller class.

    Thanks in advance.
    Last edited by Daniil; Feb 18, 2013 at 5:31 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Thanks for the report, fixed in SVN
  3. #3
    I've acquired latest files from SVN trunk. Problem solved. You may can mark this thread as closed.

    Thanks for your interest.
  4. #4
    Quote Originally Posted by cankut84 View Post
    I've acquired latest files from SVN trunk. Problem solved. You may can mark this thread as closed.

    Thanks for your interest.
    There anything we can do we are not premium member? : (
  5. #5
    Ext.NET v2.2 has been released last week. It includes that fix.

    There is the NuGet Ext.Net.MVC package.
    https://nuget.org/packages/Ext.NET.MVC/

    It is the simplest way to get the release.

Similar Threads

  1. Replies: 1
    Last Post: Jul 25, 2012, 9:52 AM
  2. DirectMethod returning a boolean
    By mark39 in forum 1.x Help
    Replies: 2
    Last Post: Dec 15, 2011, 11:46 AM
  3. [CLOSED] Submit gridpanel data in form submit
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 14, 2010, 7:25 PM
  4. [CLOSED] Boolean value as Checkbox in a GridPanel
    By fondant in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 29, 2009, 11:34 AM
  5. Replies: 3
    Last Post: May 14, 2009, 6:02 PM

Tags for this Thread

Posting Permissions