What is model.AllSpecialism? My guess would be that you are storing the "name" in the coma separated string for the "specialisms" property, not the "value".
And then in the front end of the page for Umbraco begin form:
when i generate the form in the controller im using this:
Is this the correct way of binding a checkbox list? is there more standard way of doing it? I think yes the 'specialisms' property needs i comma delimited string of id's but that would mean i have to hard code those id's in my controller when creating the checkboxes?
What you've got seems ok, but yea, I think it comes down to needing the IDs and umbraco expecting the value to be a coma separated list of those IDs, rather than the names.
Now, you should be able to lookup the prevalues using the relevant Service API (or using the umbraco library helper, but this returns XML so I don't like this method), but you will still end up needing to know something (the ID of the datatype most likely).
Basically, I think you have 2 options:
1) Hard code the ID values and hope they don't change
2) Use the Umbraco API to lookup the prevalues, but this means hard coding the DTDID
You can get creative to lookup the DTDID, but I guess it depends how defensive you want to be.
Maybe as a test, swap the names in your hard coded list of SpcialismModels to actually be the Umbraco prevalue ids and see if saving those when checked updates in the back office. This way you at least know it is down to the fact you need the ID's and not just the text labels (I'm pretty sure this is the reason though).
Tested with passing the values of the datatype checkbox list prevalue id's and hard coded them in the controller
And then on the view just added a hidden filed to pass the value, it works well but dislike the hard coding bit and thought there might be a more elegant way to do it. Not to worry its working now and thats all that matters :)
I'll look into using the Umbraco API to lookup the prevalues another time as im running out of time on this one but would be nice to see a better solution.
I think you can only get to the prevalue IDs by XML. Something like this might work. Then you wont need to hardcode the Names,ID, and you can reorder them in the backoffice with ease
System.Xml.XPath.XPathNodeIterator pv = umbraco.library.GetPreValues(1134); // The ID of your Property Type pv.MoveNext(); System.Xml.XPath.XPathNodeIterator pvi = pv.Current.SelectChildren("preValue", "");
while (pvi.MoveNext()) {
new SpecialismModel {Name = pvi.Current.Value, Selected = false, Value = pvi.Current.GetAttribute("id", "")};
Sure it's possible to do it using the umbraco.library helper, but given this is for use in MVC, I can't help think that it's a bit dirty.
I would probably suggest that we should be using the APIs instead, for example:
var services = ApplicationContext.Current.Services;
var prevalues = services.DataTypeService.GetPreValuesCollectionByDataTypeId(1234);
This is much more MVC.
But as I said in my original post, you still need to know some ID (the ID of the data type (which is true in your case too)), so you are still going to have to hard code something.
Members in v6.16 handling checkbox list data type in members properties
Hi
Creating a member in umbraco v6.1.6 i have a checkbox list data type with these values:
This is the data type for it:
Im struggling to bind the selected check boxs on the front end to save them against the meber property:
my code so far is:
its not binding the selected values? i think im close to getting this right just cant see the wood for the tree's been looking at it for so long.
Can anyone one point out where im going wrong?
What is
model.AllSpecialism
? My guess would be that you are storing the "name" in the coma separated string for the "specialisms" property, not the "value".Hi Matt
In my Model View i have setup like this
And then in the front end of the page for Umbraco begin form:
when i generate the form in the controller im using this:
Is this the correct way of binding a checkbox list? is there more standard way of doing it? I think yes the 'specialisms' property needs i comma delimited string of id's but that would mean i have to hard code those id's in my controller when creating the checkboxes?
Hi Neil,
What you've got seems ok, but yea, I think it comes down to needing the IDs and umbraco expecting the value to be a coma separated list of those IDs, rather than the names.
Now, you should be able to lookup the prevalues using the relevant Service API (or using the umbraco library helper, but this returns XML so I don't like this method), but you will still end up needing to know something (the ID of the datatype most likely).
Basically, I think you have 2 options:
1) Hard code the ID values and hope they don't change 2) Use the Umbraco API to lookup the prevalues, but this means hard coding the DTDID
You can get creative to lookup the DTDID, but I guess it depends how defensive you want to be.
Maybe as a test, swap the names in your hard coded list of SpcialismModels to actually be the Umbraco prevalue ids and see if saving those when checked updates in the back office. This way you at least know it is down to the fact you need the ID's and not just the text labels (I'm pretty sure this is the reason though).
Matt
Yep
Tested with passing the values of the datatype checkbox list prevalue id's and hard coded them in the controller
And then on the view just added a hidden filed to pass the value, it works well but dislike the hard coding bit and thought there might be a more elegant way to do it. Not to worry its working now and thats all that matters :)
I'll look into using the Umbraco API to lookup the prevalues another time as im running out of time on this one but would be nice to see a better solution.
Thanks for your help Matt.
Glad you got it working. If you were using v7 I might have had a better solution for you, but I think those are really your only "simple" options.
I think you can only get to the prevalue IDs by XML. Something like this might work. Then you wont need to hardcode the Names,ID, and you can reorder them in the backoffice with ease
Hi Paul,
Sure it's possible to do it using the umbraco.library helper, but given this is for use in MVC, I can't help think that it's a bit dirty.
I would probably suggest that we should be using the APIs instead, for example:
This is much more MVC.
But as I said in my original post, you still need to know some ID (the ID of the data type (which is true in your case too)), so you are still going to have to hard code something.
Matt
is working on a reply...