You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 08:13:57