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

如何在Umbraco中获取内容页TextBox类型属性及未知别名/ID字段详情

Alright, let's tackle both of your Umbraco questions with hands-on code examples — I'll focus on Umbraco 9+ (the current LTS) since that's what most folks are using now, but I'll drop notes for older versions too:

1. 如何在Umbraco内容页面中获取编辑器类型为TextBox的属性

If you're working directly in a Razor view (the most common scenario for front-end rendering), here's how you can pull all TextBox properties from the current content node:

// Grab the current content node (works for content pages, not media/members)
var currentContent = Umbraco.Content(Model.Id);

// Filter properties where the editor is Umbraco's built-in TextBox
var textBoxProperties = currentContent.Properties
    .Where(p => p.PropertyType.EditorAlias.Equals("Umbraco.TextBox", StringComparison.OrdinalIgnoreCase));

// Loop through and output each property's alias and value
foreach (var prop in textBoxProperties)
{
    <div>
        <strong>@prop.Alias:</strong> @prop.Value
    </div>
}

Quick notes:

  • The key here is checking PropertyType.EditorAlias — "Umbraco.TextBox" is the official alias for Umbraco's default TextBox editor.
  • For Umbraco 8 and below, replace Umbraco.Content(Model.Id) with Umbraco.TypedContent(Model.Id), and the rest of the logic stays mostly the same.
2. 如何获取Umbraco内容页面中属性类型为TextBox且别名或ID未知的字段详情

If you don't know the alias/ID of the TextBox properties and need full details (like property name, description, configuration, etc.), you'll want to target the content type's property definitions first:

var currentContent = Umbraco.Content(Model.Id);

// Get all property type definitions for TextBox editors on this content type
var textBoxPropertyDefinitions = currentContent.ContentType.PropertyTypes
    .Where(pt => pt.EditorAlias.Equals("Umbraco.TextBox", StringComparison.OrdinalIgnoreCase));

foreach (var propDef in textBoxPropertyDefinitions)
{
    // Fetch the actual value of the property from the content node
    var propertyValue = currentContent.Value(propDef.Alias);

    <div class="property-detail-card">
        <h3>@propDef.Name</h3>
        <ul>
            <li><strong>Alias:</strong> @propDef.Alias</li>
            <li><strong>Property ID:</strong> @propDef.Id</li>
            <li><strong>Description:</strong> @(string.IsNullOrEmpty(propDef.Description) ? "No description" : propDef.Description)</li>
            <li><strong>Current Value:</strong> @propertyValue</li>
            <li><strong>Editor Config:</strong> @Json.Serialize(propDef.Configuration)</li>
        </ul>
    </div>
}

What this does:

  • currentContent.ContentType.PropertyTypes gives you the definition of each property on the content type (not just the value from the current node). This lets you access metadata like the property's display name, description, and even editor settings (like max length for the TextBox).
  • We then use the property alias from the definition to pull the actual value from the content node with currentContent.Value(propDef.Alias).

内容的提问来源于stack exchange,提问作者learner_01

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:05:59