1

This is my first time with MVC so please excuse me if I am getting the terminology wrong. I am working on a PluralSight course.

My understanding is scaffolding goes to the model and creates a view when selecting Add View.

Here's my model

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace OdeToFood.Models
    {
        public class RestaurantReview
        {
            public int Id { get; set; }        
            public int Rating { get; set; }
            public string Body { get; set; }
            public string ReviewerName { get; internal set; }
            public int RestaurantId { get; set; }

        }
  }

I go to my controller action and click Add View. My view is missing ReviewerName when it is built. I add ReviewerName manually to my Create view. The ReviewerName appears to not be recognized by the Model Binder when data is added to the database.

I am unsure where to go from here. Thanks for you help!

Mel
  • 13
  • 3
  • 2
    Try switching "internal set" to just "set". That may be hiding it. https://stackoverflow.com/questions/41149630/why-default-asp-scaffolding-skips-some-of-the-model-properties-while-generating – Steve Greene Dec 06 '17 at 19:36
  • I could've sworn I changed the property before posting. That was it! Thank you. – Mel Dec 06 '17 at 22:35
  • Also, how do I mark the question complete? I looked for a check mark but don't see one. – Mel Dec 06 '17 at 23:00

1 Answers1

0

When you mark the property setter as internal, the scaffolding ignores it. Simply remove that from the property and you should be set (pun intended):

public string ReviewerName { get; set; }
Steve Greene
  • 12,029
  • 1
  • 33
  • 54