none
mvc5使用Resources错误,不知道哪里出问题了 RRS feed

  • 问题

  •     public class Product
        {
            [Key]
            [Display(Name ="编号")]
            public virtual int ProdeuctId { get; set; }
    
            [Display(Name ="所属分类")]        
            public virtual int CategoryId { get; set; }
            
            [Required(ErrorMessageResourceName ="E0002",ErrorMessageResourceType =typeof(Messages))]
            [StringLength(maximumLength:20,MinimumLength =2,ErrorMessageResourceName = "E0001", ErrorMessageResourceType =typeof(Messages))]
            [Display(Name ="产品名称")]
            public virtual string Title { get; set; }
    
            [Display(Name ="ProductPrice",ResourceType =typeof(Resources.Test))]
            public virtual double Price { get; set; }
    
            [Display(Name ="描述")]
            public virtual string Content { get; set; }
            public virtual Category Category { get; set; }
        }
    “/”应用程序中的服务器错误。
    
    因本地化失败而无法检索属性“Name”。类型“Resources.Test”不是公共的,或者不包含名称为“ProductPrice”的公共静态字符串属性。
    
    说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 
    
    异常详细信息: System.InvalidOperationException: 因本地化失败而无法检索属性“Name”。类型“Resources.Test”不是公共的,或者不包含名称为“ProductPrice”的公共静态字符串属性。
    
    源错误: 
    
    
    行 19:         </th>
    行 20:         <th>
    行 21:             @Html.DisplayNameFor(model => model.Price)
    行 22:         </th>
    行 23:         <th>
    
    源文件: d:\documents\visual studio 2015\Projects\MvcMusicStore\MvcMusicStore\Views\Product\Index.cshtml    行: 21 
    
    堆栈跟踪: 
    
    
    [InvalidOperationException: 因本地化失败而无法检索属性“Name”。类型“Resources.Test”不是公共的,或者不包含名称为“ProductPrice”的公共静态字符串属性。]
       System.ComponentModel.DataAnnotations.<>c__DisplayClass12_0.<GetLocalizableValue>b__1() +38
       System.ComponentModel.DataAnnotations.LocalizableString.GetLocalizableValue() +478
       System.Web.Mvc.CachedDataAnnotationsModelMetadata.ComputeDisplayName() +32
       System.Web.Mvc.CachedModelMetadata`1.get_DisplayName() +24
       System.Web.Mvc.Html.DisplayNameExtensions.DisplayNameHelper(ModelMetadata metadata, String htmlFieldName) +19
       System.Web.Mvc.Html.DisplayNameExtensions.DisplayNameForInternal(HtmlHelper`1 html, Expression`1 expression, ModelMetadataProvider metadataProvider) +113
       System.Web.Mvc.Html.DisplayNameExtensions.DisplayNameFor(HtmlHelper`1 html, Expression`1 expression) +55
       ASP._Page_Views_Product_Index_cshtml.Execute() in d:\documents\visual studio 2015\Projects\MvcMusicStore\MvcMusicStore\Views\Product\Index.cshtml:21
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
       System.Web.WebPages.StartPage.RunPage() +17
       System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
       System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
       System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
       System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
       System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
       System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
       System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
       System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9765045
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

    Title属性的错误提示,也使用了本地化文件,但是那个不会报错,可以正常运行,但是Price这个字段就不行了。
    资源文件和键值是存在的。

    2017年8月4日 14:06

全部回复