ASP.NET MVC - пользовательский тип данных с использованием enum - PullRequest
0 голосов
/ 07 января 2012

Я новичок в ASP.NET MVC и хотел бы создать собственный тип данных из свойства одного из моих классов. Я знаю, что это возможно, но, к сожалению, мне не хватает знаний, чтобы понять, что не так с моим кодом.

Я получаю следующее сообщение об ошибке:

"Schema specified is not valid. Errors: 
The relationship 'GarethLewisWeb.Models.Photo_Set' was not loaded because the type
'GarethLewisWeb.Models.Photo' is not available.
The following information may be useful in resolving the previous error:
The property 'Orientation' on the type 'GarethLewisWeb.Models.Photo' has a property 
type of 'GarethLewisWeb.Models.Photo+Orientations' which cannot be mapped to a
PrimitiveType."

Вот код для моего класса Photo.cs, который, я думаю, вызывает проблему.

public class Photo
{
    public int PhotoID { get; set; }
    public int PhotoOrder { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string FileLocation { get; set; }
    public Orientations Orientation { get; set; }
    public int Height { get; set; }
    public int Width { get; set; }
    public int Rating { get; set; }
    public bool FeaturedPhoto { get; set; }

    public enum Orientations
    {
        Square = 0,
        Landscape = 1,
        Portrait = 2
    }

    public virtual Set Set { get; set; }
    public virtual PhotoExif PhotoExif { get; set; }
}

Любая помощь уточняется! Спасибо.

1 Ответ

0 голосов
/ 07 января 2012

Посмотрите на CustomModelBinder, он должен решить вашу проблему, вот хорошая статья об этом

http://lostechies.com/jimmybogard/2009/03/18/a-better-model-binder/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...