Copied to clipboard

Flag this post as spam?

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


  • Damion 96 posts 331 karma points
    Apr 01, 2019 @ 15:34
    Damion
    0

    text from custom content always null in my code

    In the controller code below I have an image coming from a media picker and a string from a textbox, both name exactly as they are below.

    When I put a breakpoint on the code I can get the image url no problem but the description is always null, even though I can see it when I drill down in the model. Should I be doing it differently for a string value?

    var mainImage = page.Value<IPublishedContent>("mainImage");
    var description = page.Value<IPublishedContent>("description"); 
    model.Add(new MyModel(mainImage.Url,  description.ToString());
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 01, 2019 @ 15:35
    Alex Skrypnyk
    0

    Hi Damion

    Yes, Description should be another type, is it multiline text box property editor? RTE?

    Thanks,

    Alex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 01, 2019 @ 15:35
    Alex Skrypnyk
    0

    Try "string".

  • Damion 96 posts 331 karma points
    Apr 01, 2019 @ 15:40
    Damion
    0

    you mean string instead of a var? That results in the error

    'Cannot implicitly convert type 'Umbraco.Core.Models.PublishedContent.IPublishedContent' to 'string''

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 01, 2019 @ 15:45
    Alex Skrypnyk
    100

    no, like this:

    var description = page.Value<string>("description"); 
    
  • Damion 96 posts 331 karma points
    Apr 01, 2019 @ 15:47
    Damion
    0

    excellent, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft