Danstan Morre

Danstan Morre

  • 2.1k
  • 8
  • 531

Hot to make this condition Model.Product.Id != 0 to nullable

Jun 30 2022 2:38 AM

This is my code

    @if 
    (Model.Product.Id != 0 && Model.Product.Id > 0)
    {
        title = "Edit Product";

        <input asp-for="Product.Id" hidden />
    }

and it will generate 

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Emporium
  StackTrace:
   at AspNetCoreGeneratedDocument.Views_Product_Upsert.<>c__DisplayClass24_0.<<ExecuteAsync>b__0>d.MoveNext() in D:\Data\Visual Studio Project\Emporium\Emporium\Views\Product\Upsert.cshtml:line 9

I am just new to this stuff and I do not what to do


Answers (2)