'PizzaModel' does not contain a definition for 'NewPizza' and no accessible extension method 'NewPizza' accepting a first argument of type 'PizzaModel'

Mouhamed 1 Reputation point
2022-07-17T12:02:33.47+00:00

I have been following along this documentation

https://learn.microsoft.com/en-us/learn/modules/create-razor-pages-aspnet-core/5-exercise-create-new-razor-page-and-form

I didn't even change the any variable name still getting this error

Also I did not change any code either.

I am simply copy pasting it from documentation.
I cant understanding how could I get this errors although I am following the documentation of Microsoft!!!!!!
221586-image.png

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,165 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Rena Ni - MSFT 2,061 Reputation points
    2022-07-18T01:37:56.743+00:00

    Hi @Mouhamed ,

    Be sure add the property named NewPizza in your PizzaModel:

    public class PizzaModel : PageModel  
    {  
        public NewPizza NewPizza { get; set; }  //be sure add this....  
        public void OnGet()  
        {  
        }  
      
    }  
    

    Also be sure you have created the model:

    public class NewPizza  
    {  
        public string Name { get; set; }  
        public string Size { get; set; }  
        public int Price{ get; set; }  
        //.....  
    }  
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Rena

    1 person found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 56,026 Reputation points
    2022-07-17T17:07:40.62+00:00

    It’s a typo. Remove all the “NewPizza.”


  3. Lynn Li 1 Reputation point
    2022-11-09T09:59:19.463+00:00

    you met this error message because you did not complete the following steps.
    In following steps, you should have added "newpizza" to your PizzaModel class.

    0 comments No comments