Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Casper Andersen 126 posts 508 karma points
    Jul 28, 2015 @ 13:14
    Casper Andersen
    0

    Custom DataType into ContentService

    I have the following code

    XPathNodeIterator iterator2 = umbraco.library.GetPreValues(1075);
                iterator2.MoveNext(); //move to first
                XPathNodeIterator preValues2 = iterator2.Current.SelectChildren("preValue", "");
                while (preValues2.MoveNext())
                {
                    string preValue2 = preValues2.Current.Value;
                    int preValueId2 = preValues2.CurrentPosition;
    
                    ListeOfTeamNumbers.Add(new SelectListItem
                    {
                        Text = preValue2,
                        Value = preValue2
                    });
                    modal.ListeOfTeamNumbers = ListeOfTeamNumbers;
    

    which will grab the datatype i have and send the values to a dropdownlist. This Works perfectly, but then when i want to grab the value and add it inside my ContentService.CreateContent like this

    var nytHold = Services.ContentService.CreateContent(modal.SelectedYear + " - " + modal.SelectedTeamNumber.ToString(), 1161, "Hold");
                nytHold.SetValue("argang", modal.SelectedYear);
                nytHold.SetValue("holdnummer", modal.SelectedTeamNumber);
                nytHold.SetValue("holdetsTilknyttedeTraenere", modal.ListOfSelectedClubs);
                nytHold.SetValue("holdetsKlub", modal.ListOfSelectedTrainers);
                Services.ContentService.SaveAndPublishWithStatus(nytHold);
                TempData["formStatus"] = "Holdet blev oprettet";
                return RedirectToCurrentUmbracoPage();
    
  • Mark Bowser 273 posts 860 karma points c-trib
    Jul 28, 2015 @ 16:32
    Mark Bowser
    0

    Do you get an error when you do this? Or do you just get unexpected results? Can you send over more details on what happens when you try to create the new content using the ContentService?

  • Casper Andersen 126 posts 508 karma points
    Jul 28, 2015 @ 16:45
    Casper Andersen
    0

    Yeah sure, well everything goes through fine, but in my backend on the newly created node, none of the properties are filled with the information, they just appear blank

  • Casper Andersen 126 posts 508 karma points
    Jul 29, 2015 @ 09:26
    Casper Andersen
    100

    Nevermind, after really digging through the internet today i found my solution.

    // Årgang is the name of my datatype, NOTE the name not the Alias
    // and the modal.SelectedYear is the value im passing into the controller from my view's selected dropdown value
        DataTypeService myService = new DataTypeService();
                    var SelectedYear = myService.GetAllDataTypeDefinitions().First(x => x.Name == "Årgang");
                    int SelectedYearPreValueId = myService.GetPreValuesCollectionByDataTypeId(SelectedYear.Id).PreValuesAsDictionary.Where(x => x.Value.Value == modal.SelectedYear).Select(x => x.Value.Id).First();
    
Please Sign in or register to post replies

Write your reply to:

Draft