Copied to clipboard

Flag this post as spam?

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


  • James 251 posts 1169 karma points
    Feb 11, 2015 @ 09:51
    James
    0

    Cannot perform runtime binding on a null reference

    Hello all,

    I have the following code which is returning an error as below:

    Cannot perform runtime binding on a null reference

    Does anyone have any ideas why this would be happening? - Using Umbraco 6

     

    var queryStringId = Request.QueryString["id"];

       if(queryStringId != null )

        {

            @Model.feedbackText

        }

        else

        {

            @Model.contactUsText

        }

     

     

    Kindest regards,

     

    J

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 11, 2015 @ 09:56
    Jan Skovgaard
    0

    Hi James

    Perhaps it's the way you're doing your test.

    Try testing like this instead

    if(!String.IsNullOrEmpty(querystringId.ToString())){
      // Your code here
    }
    

    Hope this helps.

    /Jan

  • James 251 posts 1169 karma points
    Feb 11, 2015 @ 10:13
    James
    0

    Thanks for your response. This hasn't worked either:

     

    string queryStringId = Request.QueryString["id"];

     

     

       if (String.IsNullOrEmpty(queryStringId))

        {

           

            @Model.contactUsText

        }

        else

        {

            @Model.feedbackText

        }

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 11, 2015 @ 10:17
    Jan Skovgaard
    0

    Hi James

    What happens if you cast the querystringId to a string, like I did in my example? Just to make sure that the value can't be interpreted as anything else than a string when you're validating it.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft