MRCollective/ChameleonForms

Complications with binding model.

Closed this issue · 3 comments

Here is my model:

class Model
{
public List<AdminPermission> Names { get; private set; }
// another fileds
}

AdminPermission is an enum with values.
ViewModel looks like this:

@s.FieldFor(x => x.Names).AsCheckboxList()
// views for another fields

GET controller method for this view follows:

Model perm = new Model();
perm.Names.AddRange(grp.AdminPermissions);
return this.View(perm);

POST controller method signature is:

public ActionResult Method(Model result)

In this case binding won't work. Model.Items is empty, another fields filled successfull. I've debugged POST request with Fiddler, it gaves me suggestion to workaround the issue by changing signature:

public ActionResult Method(Model result, List<AdminPermission> names)

and it works.
Looks like you've missed name of parent in html name generating.

Sorry I haven't had a chance to look at this yet - it is in my list. I'm in the middle of preparing for some presentations at the moment. @MattDavies has been pretty busy too. I'm sure one of us will find time over the next few days.

In the meantime, can you paste the html of that field that is generated?

Looks like there was my misunderstanding or some bug. I've refactored my code - and it's worked well as supposed to. I think my problem in misuse access modifiers for fields in my viemodel.

Glad to hear your problem is sorted :)