CS1061:不包含定义
为什么我会收到此错误? 当然,我的第一个模型上不存在SelectIssuePriority。 我添加了它。
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1061: 'Devcore' does not contain a definition for 'SelectIssuePriority' and no extension method 'SelectIssuePriority' accepting a first argument of type 'Devcore.' could be found (are you missing a using directive or an assembly reference?) Source Error: Line 77: Line 78: Line 79: model.SelectIssuePriority) %> Line 80: Line 81:
模型
namespace Devcore.Models { [MetadataType(typeof(IssueMetaData))] public partial class Issue { } public class IssueMetaData { [Required(ErrorMessage="Summary is required",AllowEmptyStrings = false)] public string Summary { get; set; } [Display(Name = "Priority")] [Required(ErrorMessage = "Priority is required", AllowEmptyStrings = false)] public string SelectIssuePriority { get; set; } } }
ASPX
model.SelectIssuePriority) %> model.SelectIssuePriority) %>
IIRC,那些MetaData
扩展类纯粹用于validation。 如果您的基本模型没有这些属性..它将无法工作。
所以你需要这个以使视图接受存在的属性:
[MetadataType(typeof(IssueMetaData))] public partial class Issue { public string SelectIssuePriority { get; set; } }
并且您需要DataAnnotations
的MetaData
类才能使用模型validation。