{"record":{"id":"53fc5f53a3c7248c","repo":"OrchardCMS/OrchardCore","slug":"the-name-attribute-can-t-be-empty","errorCode":null,"errorMessage":"The name attribute can't be empty","messagePattern":"The name attribute can't be empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/ZoneTagHelper.cs","lineNumber":33,"sourceCode":"    private readonly ILogger _logger;\n\n    public ZoneTagHelper(ILayoutAccessor layoutAccessor, ILogger<ZoneTagHelper> logger)\n    {\n        _layoutAccessor = layoutAccessor;\n        _logger = logger;\n    }\n\n    [HtmlAttributeName(PositionAttribute)]\n    public string Position { get; set; }\n\n    [HtmlAttributeName(NameAttribute)]\n    public string Name { get; set; }\n\n    public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)\n    {\n        if (string.IsNullOrEmpty(Name))\n        {\n            throw new ArgumentException(\"The name attribute can't be empty\");\n        }\n\n        var childContent = await output.GetChildContentAsync();\n        var layout = await _layoutAccessor.GetLayoutAsync();\n\n        var zone = layout.Zones[Name];\n\n        if (zone is Shape shape)\n        {\n            await shape.AddAsync(childContent, Position);\n        }\n        else\n        {\n            _logger.LogWarning(\n                \"Unable to add shape to the zone using the <zone> tag helper because the zone's type is \" +\n                \"\\\"{ActualType}\\\" instead of the expected {ExpectedType}\",\n                zone.GetType().FullName,\n                nameof(Shape));","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/ZoneTagHelper.cs#L15-L51","documentation":"ZoneTagHelper creates or retrieves a named zone on the layout when a <zone> element is processed. The Name attribute is mandatory: if it is missing or empty, ProcessAsync throws ArgumentException immediately. This ensures zones are always addressable by a non-empty key in ThemeLayout.Zones.","triggerScenarios":"Writing <zone></zone> or <zone Name=\"\"></zone> in a Razor template, or binding Name to a model property/variable that evaluates to null or empty string at render time.","commonSituations":"Forgotten Name attribute; dynamic Name=\"@Model.ZoneName\" where the value is empty; typos like name=\"\" (case/wrong attribute casing not mapped to the helper property).","solutions":["Add a non-empty Name attribute: <zone Name=\"Content\" />","If the name is dynamic, validate it is non-empty before rendering the zone tag","Check attribute casing — the tag helper property is Name","Guard the razor code: only emit the <zone> element when the computed name is present"],"exampleFix":"// before\n<zone Name=\"@Model.ZoneName\"></zone>\n// after\n@if (!string.IsNullOrEmpty(Model.ZoneName))\n{\n    <zone Name=\"@Model.ZoneName\"></zone>\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(zoneName)) { throw new ArgumentException(\"Zone name must be provided\", nameof(zoneName)); }\n// then render: <zone Name=\"@zoneName\"></zone>","typeGuard":null,"tryCatchPattern":"try { await next(output); } catch (ArgumentException e) when (e.Message.Contains(\"name attribute\")) { output.SuppressOutput(); }","preventionTips":["Always include a literal or validated Name attribute on <zone> elements","Null-check dynamic zone names before emitting the tag","Keep attribute casing as Name for the tag helper binding"],"tags":["taghelpers","zones","razor","validation"],"backgroundTag":"empty-required-field","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}