When I load the class in the view, it gives Nullexception error

Asked

Viewed 110 times

-2

That’s the mistake you’re making:

inserir a descrição da imagem aqui

This is the error line in my cshtml

@( new HtmlString((SessaoUtil.Recuperar("TagGoogle") != null ? SessaoUtil.Recuperar("TagGoogle").ToString() : "")))

This is my using in my cshtml

@model AgaxTurSiteOficial.Entities.PackageSearchInfo

This is my Packagesearchinfo class

public class PackageSearchInfo
    {
        public int chkpacotesroteiros { get; set; }
        public int chkaereo { get; set; }
        public int chkhotel { get; set; }
        public int chkaluguelcarro { get; set; }
        public int chkcruzeiros { get; set; }
        public int chkingressos { get; set; }
        public int chkseguro { get; set; }


        public string txtDestino { get; set; }
        public string txtOrigem { get; set; }
        public string mesViagem { get; set; }
        public string datIda { get; set; }
        public string datVolta { get; set; }
        public int intAdultos { get; set; }
        public int intCriancas { get; set; }
        public int quaAdulto { get; set; }
        public int quaCrianca { get; set; }
        public int quaMaisCinco { get; set; }
        public int idGeoAreDestino { get; set; }
        public int idGeoAreOrigem { get; set; }
        public string idPacotes { get; set; }
        public string SubMit { get; set; }


        public string localPagina { get; set; }
        public string[] passos { get; set; }

    }

Honestly, I have another cshtml, with the same information that works. This procedure is standard for all our pages. I’m checking the other pages to see where it’s different, but I can’t find anything. Of course something is missing, but I don’t know what it is. I posted everything to try to help colleagues, giving as much information, because help the distance I know is bone. If any more relevant information is missing, just ask me to edit the post and send.

Sorry for the wrong information. The error line in my CSHTML is this.on top of Model.chkpacotesscripts != 0:

@{
     if (Model.chkpacotesroteiros != 0)
    {
         @Model.mesViagem
    }
     else
    {
         @Model.datIda @:<br />a @Model.datVolta
    }

}
  • 1

    The error is not in any code snippet of the ones you posted. Hint: the Debugger is your friend. Apparently you are already debugging the code. See which line the program stops on. Type exceptions NullReferenceException occur when you try to perform an operation on a null variable. And only check your variables one by one on the line where the error happens.

  • This is the error line. It was misspelled by me. @( new Htmlstring((Sessaoutil.Recover("Taggoogle") != null ? Sessaoutil.Recover("Taggoogle"). Tostring() : "")))

  • 3

    SessaoUtil is static?

  • I take back what I said about the error not being in the codes posted. What the Gypsy said makes perfect sense.

  • Your doubt is authentic @pnet, however, I don’t know if this issue will be really useful to other users in the future... because it seems it was a mere lack of attention. If that’s the case, I’d rule her out.

1 answer

1

Well, I know it’s hard for anyone to solve problems remotely. And sometimes we have trouble giving the most accurate information. Often we post where the problem bursts, but often not where it starts. I put a few things so that colleagues could analyze and help me in the solution, but I was not happy to post all the code, because as this forum agent may not be posting much, I prefer to try to be lean, but I actually posted parts that was not the problem. It burst there, but it was not the issue. In my Action, I have the Sourcepackageinfo object and assign the package variable to that object. In Action’s Return, it should look like this: Return View(package); and it looked like this: Return View(); there was the question. The object was not being passed to the View and therefore gave Nullexception error. It was not intentional, because honestly, if I knew, I would not have done the post. For those of us with the problem, even asking the question is not always easy. I count on the understanding of all, for my goal here is to help the forum to develop more and more. But I thank everyone who tried to help me and even helped me a lot. I will mark Renan’s response, but the Gypsy also deserves to have his answer marked. I do not know if I can score two, I think not. Until +++.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.