Search code examples
orchardcms

How to Add id attribute to a tag in orchard alternates


I use Orchard CMS 1.10.1. I have created an alternate for a menu, I know how to add a class attribute to a tag

var tag = Tag(Model, "ul");
tag.AddCssClass("class-custom");

I need to add an id attrubite to this ul tag. How can I do this?


Solution

  • You can use one of the following methods to add custom attributes:

    1. Add attribute to shape before create the tag:
    Model.Attributes.Add("id", "blah");
    var tag = Tag(Model, "ul");
    
    1. Add attributes after create tag:
    var tag = Tag(Model, "ul");
    tag.MergeAttribute("id", "blah");
    
    1. Add "Id" attribute to shape (only applicable for id attribute):
    Model.Id = "blah";
    var tag = Tag(Model, "ul");