2013-08-29 52 views
0
的定义

为什么我得到这个错误?当然,SelectIssuePriority在我的第一个模型中不存在。我已添加它。CS1061:不包含

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> 

回答

1

IIRC,那些MetaData扩展类纯粹是为了验证。如果你的基础模型没有这些属性..它不会工作。

所以,你需要这个观点接受性能存在:

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

而且需要具备MetaData类的DataAnnotations与模型验证工作。

+0

谢谢你更快的回复。这么快,我无法解决这个问题。 – AFetter

相关问题