我如何解决Modelstate.Isvalid始终为假。 [英] How Do I Can Resolve Modelstate.Isvalid Always False.

查看:106
本文介绍了我如何解决Modelstate.Isvalid始终为假。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有我的模型,我无法编辑它。



我的ModelState上的错误返回:

There's my Model, and i can't Edit it.

The errors on my ModelState returns:

var errors = ModelState.Values.SelectMany(v => v.Errors);



[0] - 字段名称是必需的。

[1] - 字段ID是必需的。

[2] - 字段名称是必需的。




[0] - "The Field Name is Required."
[1] - "The Field Id is Required."
[2] - "The Field Name is Required."

public class Document
    {   
        [Key]
        public int Id { get; set; }

        [Required]
        [Display(Name = "Nome")]
        public string Name { get; set; }

        [Display(Name = "Descrição")]
        public string Description { get; set; }
                
        [Display(Name = "Arquivo")]
        public string Path { get; set; }

        [Required]        
        [Display(Name = "Categoria")]
        [Range(1, int.MaxValue, ErrorMessage = "Selecione uma categoria válida.")]
        public DocumentCategory Category { get; set; }
        
        [Display(Name="Privado")]
        public bool isPrivate { get; set; }
                
        public DateTime? InsertDate { get; set; }
        public DateTime? UpdateDate { get; set; }

        [Display(Name = "Playlist")]
        public int? PlaylistID { get; set; }

        [Display(Name = "Album")]
        public int? AlbumID { get; set; }

        public virtual Album Album { get; set; }
        public virtual Playlist Playlist { get; set; }     
        public virtual MyUser User { get; set; }
    }







帮助我。谢谢。




Help me. Thanks.

推荐答案

呃,这看起来像是一个愚蠢的回应,但你是否尝试提供它想要的所需信息?



看起来好像你试图在视图模型的位置使用实体模型。
Uhhh, this may seem like a stupid response, but did you try supplying the required information it wants??

It appears as though you're trying to use entity models in the place of a view model.


这篇关于我如何解决Modelstate.Isvalid始终为假。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆