Razor proxy type error. System.Data.Entity.DynamicProxies

前端 未结 2 417
北恋
北恋 2021-01-15 12:59

I have a class User and then another Type UserSpecial with some special user properties. I pass it in razor to the partial method class to create the UserSpecial form which

2条回答
  •  不要未来只要你来
    2021-01-15 13:10

    The solution for this issue is pretty simple:

    You should just use a wrapper class (view model) as Darin suggested.

    So for example:

    (entity domain model):

    public class MyEntityModel
    {
        public int Id { get; set; }
        public String Name { get; set; }
    }
    

    => put it in a ViewModel (just a stupid wrapper) should result in this

    public class MyViewModel
    {
        public MyEntityModel MyEntityModel { get; set; }
    }
    

    Now, in the view, u should be able to access the "name" property by doing this

    The entity object's name is "@model.MyEntityModel.Name"

    (notice you should not use @model.Name!)

提交回复
热议问题