ASP.NET MVC Scaffolding View - Missing Model Property

雨燕双飞 提交于 2019-12-23 01:01:44

问题


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:


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; }


来源:https://stackoverflow.com/questions/47682071/asp-net-mvc-scaffolding-view-missing-model-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!