CS1061:不包含针对的定义

编程入门 行业动态 更新时间:2024-10-25 06:28:57
本文介绍了CS1061:不包含针对的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么会出现此错误?当然,我的第一个模型中不存在SelectIssuePriority.我已经添加了.

Why I get this error? Of course SelectIssuePriority doesn't exist on my first model. I have add it.

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: <div class="editor-label"> Line 79: <%: Html.LabelFor(model => model.SelectIssuePriority) %> Line 80: </div> Line 81: <div class="editor-field">

型号

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

<div class="editor-label"> <%: Html.LabelFor(model => model.SelectIssuePriority) %> </div> <div class="editor-field"> <%: Html.DropDownList("SelectIssuePriority") %> <%: Html.ValidationMessageFor(model => model.SelectIssuePriority) %> </div>

推荐答案

IIRC,这些MetaData扩展类仅用于验证.如果您的基本模型没有这些属性,那么它将无法正常工作.

IIRC, those MetaData extension classes are purely for validation. If your base model doesn't have those properties.. it won't work.

因此,您需要此视图才能接受存在的属性:

So you need this for the view to accept that properties exist:

[MetadataType(typeof(IssueMetaData))] public partial class Issue { public string SelectIssuePriority { get; set; } }

并且您需要MetaData类用于DataAnnotations以便进行模型验证.

And you need the MetaData class for the DataAnnotations to work with model validation.

更多推荐

CS1061:不包含针对的定义

本文发布于:2023-11-09 10:26:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不包含   定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!