ASP.NET MVC Scaffolding View - Missing Model Prope

2019-06-03 08:19发布

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!

1条回答
▲ chillily
2楼-- · 2019-06-03 09:06

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; }
查看更多
登录 后发表回答