Umbraco 12.3.4遇CS1061错误:'Model'不存在'oTitle'定义
问题场景
基于Umbraco 12.3.4开发项目,已安装OskiStarterKit 3.0.2。创建带模板的文档类型、添加组合、填充内容后生成模型,在Product.cshtml中调用@Model.oTitle时出现报错。
相关代码
Product.cshtml
@using Umbraco.Cms.Web.Common.PublishedModels; @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.Product> @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels; @{ Layout = null; } <!DOCTYPE html> <html> <head> <title>@Model.oTitle</title> </head>
生成的Product模型属性
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "12.3.4+4a0d364")] [global::System.Diagnostics.CodeAnalysis.MaybeNull] [ImplementPropertyType("oTitle")] public virtual string OTitle => global::Umbraco.Cms.Web.Common.PublishedModels.OCardsContainer.GetOTitle(this, _publishedValueFallback);
报错信息
'Product' does not contain a definition for 'oTitle' and no accessible extension method 'oTitle' accepting a first argument of type 'Product' could be found (are you missing a using directive or an assembly reference?)
问题原因
核心是C#大小写敏感导致的属性名称不匹配:
- 生成的模型中,对应属性的名称是
OTitle(首字母大写) - 视图代码里调用的是
oTitle(首字母小写)
两者名称大小写不一致,编译器无法识别匹配的属性,因此抛出错误。
内容的提问来源于stack exchange,提问作者Malek Mshinesh
相关产品推荐
相关产品推荐

