MRCollective / ChameleonForms

Shape-shifting your forms experience in ASP.NET Core MVC
MIT License
254 stars 56 forks source link

Complications with binding model. #86

Closed zabulus closed 10 years ago

zabulus commented 10 years ago

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.

robdmoore commented 10 years ago

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?

zabulus commented 10 years ago

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.

robdmoore commented 10 years ago

Glad to hear your problem is sorted :)