Home ASP.NET MVC Scaffolding View - Missing Model Property
Reply: 1

ASP.NET MVC Scaffolding View - Missing Model Property

Mel
1#
Mel Published in 2017-12-06 19:29:33Z

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!

Steve Greene
2#
Steve Greene Reply to 2017-12-07 14:57:06Z

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; }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.318297 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO