Copied to clipboard

Flag this post as spam?

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


  • Patrick van Kemenade 25 posts 136 karma points
    4 days ago
    Patrick van Kemenade
    0

    Macro parameter of type integer containing string "null"

    I notice strange behavour with a macro parameter called with which is set as an integer type.

    When I first use this macro and don't set a with, the Model.MacroParameters["width"] contains "" (emty string)

    When I set it to a value for instance 1 it becomes "1"

    When I clear it again an rerun, it becomes "null", so my String.IsNullOrWhitespace fails because it literay containg "null"

    So a Macro parameter of type int can become, "", "1", "null" (string value), can it also become

    You can't use Convert.ToInt32(Model.MacroParameters["width"]) which I see in some examples because this crashes on the string "null".

    Or is the Int parameter not supposed to be used at all and everybody only uses string parameters ? Or is this a known Umbraco bug?

    I'm using Umbraco 8.6.1.

  • Patrick van Kemenade 25 posts 136 karma points
    4 days ago
    Patrick van Kemenade
    0

    After more testing, this behaviour only seems to occur on parameter type of int not on string value, otherwise you couldn't distinguish is somebody actually typed the string "null" or if it's empty.

    So it's fixable by just adding:

    string width = (string)Model.MacroParameters["width"]; if (width == "null") { width = null; } // now you can convert the width to a int?

Please Sign in or register to post replies

Write your reply to:

Draft