Copied to clipboard

Flag this post as spam?

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


  • Christina 127 posts 390 karma points notactivated
    May 04, 2018 @ 14:05
    Christina
    0

    Problem getting value from radiobuttonlist with Umbraco.GetPreValueAsString

    Hi can someone see whats wrong with my code

    I have this in a PartialView

    var scolor=Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("PuffColor");
    var color=Umbraco.GetPreValueAsString(scolor);
    

    I revice an error

    CS1502: The overlay method that best matches int.Parse (string) has some invalid arguments

    Thanks Christina

  • Sven Geusens 169 posts 881 karma points c-trib
    May 04, 2018 @ 15:10
    Sven Geusens
    1

    Hey Christina

    In your first line you are asking to transform the value in the "PuffColor" property into a IPublishedContent

    Next you are asking to retrieve the string of the prevalue base on a numerical string value.

    An IPublishedContent is not a numerical string, it is an object.

    Depending on your umbraco version, you can get the string value immediatly

    Try rendering the value of the puffcolor straight away

    @Umbraco.AssignedContentItem.GetPropertyValue<string>("PuffColor")
    

    if that renders a number, fetch it trough the prevalues

    var colorIdAsString=Umbraco.AssignedContentItem.GetPropertyValue<string>("PuffColor");
    var color=Umbraco.GetPreValueAsString(colorIdAsString);
    

    As a sideNode, why are you doing Umbraco.AssignedContentItem? When you call a partialView, you automatically pass the model from the View you are on. So if your Main view/template and the partialView have the same inherit at the top @inherits Umbraco.Web.Mvc.UmbracoTemplatePage or @inherits Umbraco.Web.Mvc.UmbracoViewPage you can just use Model.GetPropertyValue

  • Christina 127 posts 390 karma points notactivated
    May 04, 2018 @ 16:09
    Christina
    0

    Hi Sven Thanks alot but i still have problem I have a masterpage from where I call the Partvial View and I wanted to access i from the sub page with another template. It doesn't work with the Model.GetPropertyValue, so i hade to use var color=Umbraco.AssignedContentItem.GetPropertyValue("PuffColor"); But i Noticed that I can use item @Umbraco.Field("puffColor") I still have a problem to convert

     var color=Umbraco.GetPreValueAsString(colorIdAsString);
    

    CS1502: The overlay method that best matches Umbraco.Web.UmbracoHelper.GetPreValueAsString (int) has some invalid arguments /Christina

  • Sven Geusens 169 posts 881 karma points c-trib
    May 07, 2018 @ 07:46
    Sven Geusens
    0

    Does Model.Content.GetPropertyValue work? (if not, show me the line that start with @inherits in the template where you are placing this code)

    try var color=Umbraco.GetPreValueAsString(Convert.ToInt32(colorIdAsString));

  • Christina 127 posts 390 karma points notactivated
    May 07, 2018 @ 07:56
    Christina
    0

    Hi Sven Many Thanks I have solved it /C

Please Sign in or register to post replies

Write your reply to:

Draft