CS1061: does not contain a definition for

泪湿孤枕 提交于 2019-12-08 12:00:16

问题


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">

Model

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>

回答1:


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; }
}

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



来源:https://stackoverflow.com/questions/18501120/cs1061-does-not-contain-a-definition-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!