以下の Razor 構文を使用できるように、連鎖可能な HtmlAttribute クラスといくつかの Html 拡張メソッドを考え出しました。
<ul> 
    @foreach (var mi in items) { 
    <li @Html.Css("selected", mi.Selected)> 
        <a href="@mi.Href" @Html.Attr("title", mi.Title)>@mi.Text</a> 
    </li> 
    } 
</ul> 
HtmlAttribute クラスは次のとおりです。
public class HtmlAttribute : IHtmlString     
{
    private string _InternalValue = String.Empty;
    private string _Seperator;
    public string Name { get; set; }
    public string Value { get; set; }
    public bool Condition { get; set; }
    public HtmlAttribute(string name)
        : this(name, null)
    {
    }
    public HtmlAttribute( string name, string seperator )
    {
        Name = name;
        _Seperator = seperator ?? " ";
    }
    public HtmlAttribute Add(string value)
    {
        return Add(value, true);
    }
    public HtmlAttribute Add(string value, bool condition)
    {
        if (!String.IsNullOrWhiteSpace(value) && condition)
            _InternalValue += value + _Seperator;
        return this;
    }
    public string ToHtmlString()
    {
        if (!String.IsNullOrWhiteSpace(_InternalValue))
            _InternalValue = String.Format("{0}=\"{1}\"", Name, _InternalValue.Substring(0, _InternalValue.Length - _Seperator.Length));
        return _InternalValue;
    }
}
追加情報: 「セパレーター」は、属性の複数の値を連結するために使用されます。これは、複数の css クラス名 (スペースを使用) に役立ちます。また、おそらく String.Empty を使用して、複数の条件に依存する値を作成します (.Add() メソッドを使用)。
Html 拡張ヘルパー メソッドは次のとおりです。
public static class Extensions
{
    public static HtmlAttribute Css(this HtmlHelper html, string value)
    {
        return Css(html, value, true);
    }
    public static HtmlAttribute Css(this HtmlHelper html, string value, bool condition)
    {
        return Css(html, null, value, condition);
    }
    public static HtmlAttribute Css(this HtmlHelper html, string seperator, string value, bool condition)
    {
        return new HtmlAttribute("class", seperator).Add(value, condition);
    }
    public static HtmlAttribute Attr(this HtmlHelper html, string name, string value)
    {
        return Attr(html, name, value, true);
    }
    public static HtmlAttribute Attr(this HtmlHelper html, string name, string value, bool condition)
    {
        return Attr(html, name, null, value, condition);
    }
    public static HtmlAttribute Attr(this HtmlHelper html, string name, string seperator, string value, bool condition)
    {
        return new HtmlAttribute(name, seperator).Add(value, condition);
    }
}
それらが役に立つかどうか教えてください。
ありがとう、
リー