Copied to clipboard

Flag this post as spam?

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


  • nic 7 posts 87 karma points
    Oct 13, 2013 @ 13:31
    nic
    0

    Error when setting a variable to null

    I am trying to set a variable to the url of the previous page, however there is no previous page:

     

     string url_prev = "";

    if(!string.IsNullOrEmpty(Model.Content.Previous().Url))

    {

    url_prev = Model.Content.Previous().Url;

    }

     

    but this gives the following error:

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

     

    can anyone help?

    cheers

    Nic

     

     

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 13, 2013 @ 13:36
    Ali Sheikh Taheri
    0

    this is your solution

    if(Model.Content.Previous()!= null))
    {
        url_prev = Model.Content.Previous().Url;
    }
    
  • nic 7 posts 87 karma points
    Oct 13, 2013 @ 14:05
    nic
    100

    perfect, thank you

Please Sign in or register to post replies

Write your reply to:

Draft