Unexpected behaviour from CslaModelBinder 4.1

Unexpected behaviour from CslaModelBinder 4.1

Old forum URL: forums.lhotka.net/forums/t/10505.aspx


j0552 posted on Friday, July 08, 2011

Hi

I'm using the ProjectTracker sample code which accompanies the Csla4 MVC ebook.

I've noticed that the CslaModelBinder is not working as I would expect.

if I comment out

@*@Html.EditorFor(model => model.Name)*@

in the create.cshtml view and post a new project to this action:

        public ActionResult Create(FormCollection collection)
        {
            var project = ProjectEdit.NewProject();

            try
            {
                UpdateModel(project, collection);
            }
            catch (Exception)
            {
                ViewData.Model = project;
            }
            return View();
        }


the brokenrule does not get added to the ModelState.

if I use the DefaultModelBinder it does get added.


This would be more of a problem if there was an unselected radio button which needed to bind to a property with the [Required] attribute for example. I don't think this is desirable.

Can you suggest a solution for this?

Thanks
Andrew

 

RockfordLhotka replied on Saturday, July 09, 2011

This sounds like a bug in the model binder. I've added it to the bug list: http://www.lhotka.net/cslabugs/edit_bug.aspx?id=938

Copyright (c) Marimer LLC