Save Dropdown list, checkbox list value in Content Page In Umbraco 8.1.0
Hello All,
I make one custom registration form that I use the dropdown list, checkbox list and some other textbox fields (Firstname, email, Password), etc.
For dropdown list bind using master content node get from the back office.
var job titles = Umbraco.Content(1216);
For multiple checkbox list bind, data type(Hobbies checkbox list) value gets from the back office.
var hobbiesCheckboxList = Services.DataTypeService.GetDataType(1495);
Now I want to save the dropdown selected value and multiple checkbox list selected value in the content page.
Dropdown selected value save as content picker value in the back office for this I do the following code.
var registrationContent = _contentService.Create(model.FullName, 1497, "registration");
registrationContent.SetValue("jobTitle", model.JobTitle);r
egistrationContent.SetValue("hobbies", model.Hobbies);
Using the above code I save the content page only but when clicking on display detail page then I can`t get the dropdown selected value and checkbox list selected value displays in the content page in the back office.
So any have an idea about how to pass dropdown selected value set in the content picker, set checkbox list as multiple selected value using the surface controller method in Umbraco 8.1.0 on a submit the form.
I do the numbers of R&D to find the solution but not get any success. So please help me solve out this as soon as possible.
You need to store UDI in the content node. Now, you cannot store ID in the content node.
Try this:-
var jobNode = Umbraco.Content(model.JobTitle);
var udi = new GuidUdi("document", jobNode.GetKey());
registrationContent.SetValue("jobTitle", udi.ToString());
I got the solution with minor changes in your comment.
var jobNode = Umbraco.Content(model.JobTitle);
var jobUdi = new GuidUdi("document", jobNode.Key);
registrationContent.SetValue("jobTitle", jobUdi.ToString());
This work for passing the dropdown selected value in the content node picker.
Please if you same solution for checkbox list selected then tell me so its better to implementing
Related to checkbox list selected value save in content page using below code.
var hobbiesCheckboxList = Services.DataTypeService.GetDataType(1495);
var checkList = model.Hobbies.TrimEnd(',').Split(',');
var hobbiesList = ((Umbraco.Core.PropertyEditors.ValueListConfiguration)hobbiesCheckboxList.Configuration)
.Items;
var commStringHobbies = string.Empty;
foreach (var selectedId in checkList)
{
foreach (var item in hobbiesList)
{
if (Convert.ToInt32(selectedId) != item.Id) continue;
if (string.IsNullOrEmpty(commStringHobbies))
commStringHobbies = item.Value + ',';
else
commStringHobbies += item.Value + ',';
}
}
commStringHobbies = "['" + commStringHobbies.TrimEnd(',').Replace(",", "','") + "']";
var registrationContent = _contentService.Create(model.FullName, parentId, "registration");
registrationContent.SetValue("hobbies", commStringHobbies);
This is I think some worst solution but its work in version 8.1.0. if you get an any better solution to save checkbox list selected value then tell me so I can implement that one.
Save Dropdown list, checkbox list value in Content Page In Umbraco 8.1.0
Hello All,
I make one custom registration form that I use the dropdown list, checkbox list and some other textbox fields (Firstname, email, Password), etc.
For dropdown list bind using master content node get from the back office.
For multiple checkbox list bind, data type(Hobbies checkbox list) value gets from the back office.
Now I want to save the dropdown selected value and multiple checkbox list selected value in the content page.
Dropdown selected value save as content picker value in the back office for this I do the following code.
Using the above code I save the content page only but when clicking on display detail page then I can`t get the dropdown selected value and checkbox list selected value displays in the content page in the back office.
So any have an idea about how to pass dropdown selected value set in the content picker, set checkbox list as multiple selected value using the surface controller method in Umbraco 8.1.0 on a submit the form.
I do the numbers of R&D to find the solution but not get any success. So please help me solve out this as soon as possible.
Thanks in Advance.
Hi,
You need to store UDI in the content node. Now, you cannot store ID in the content node.
Try this:- var jobNode = Umbraco.Content(model.JobTitle); var udi = new GuidUdi("document", jobNode.GetKey()); registrationContent.SetValue("jobTitle", udi.ToString());
This is useful link:- https://our.umbraco.com/documentation/reference/querying/Udi
Thanks, Shaishav,
I got the solution with minor changes in your comment.
var jobNode = Umbraco.Content(model.JobTitle); var jobUdi = new GuidUdi("document", jobNode.Key); registrationContent.SetValue("jobTitle", jobUdi.ToString());
This work for passing the dropdown selected value in the content node picker.
Please if you same solution for checkbox list selected then tell me so its better to implementing
Thanks a lots.
Hi Everyone,
Related to checkbox list selected value save in content page using below code.
This is I think some worst solution but its work in version 8.1.0. if you get an any better solution to save checkbox list selected value then tell me so I can implement that one.
Hi Mihir,
Your code snippet works well. Thank you very much!
I have to spend some time understanding the exact string value required by SetValue() method.
Following is are the dropdown values I wanted to have selected when I save the node programmatically and below is the json string I set is to...
data from external sources
"Draft,Cargo Condition,Port Captain Service,"
Actual string format requried to successfully save the node
"['Draft','Cargo Condition','Port Captain Service']"
Thanks,
Ranjit
is working on a reply...