when passing a collection to EditorFor(), it generates invalid names for input elements

前端 未结 6 1701
心在旅途
心在旅途 2021-02-06 02:06

I have a BookCreateModel which consists of book\'s plane info such as Title, PublishYear & etc plus a collection of book Authors (complex type) :

public clas         


        
6条回答
  •  长发绾君心
    2021-02-06 02:36

    I didn't find any solution to this bug yet, but as a workaround I changed my UpdateModel by using a custom wrapper class instead of using a collection directly :

    public class BookCreateModel
    {
        public string Title { get; set; }
        public int Year { get; set; }
        public BookAuthorsList Authors { get; set; }
    }
    
    public class BookAuthorsList
    {
        public IList AuthorsList { get; set; }
    }
    
    public class AuthorEntryModel
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
    

    and thus generated inputs wouldn't make naming issues anymore :)

    
    
    

提交回复
热议问题