【发布时间】:2011-09-04 14:22:54
【问题描述】:
我在 asp.net mvc2 项目中创建了 Html 帮助类:
public static class CaptionExtensions
{
public static string Captions(this HtmlHelper helper, Captions captions)
{
var sb = new StringBuilder();
sb.AppendLine("<ul>");
foreach (var caption in captions)
{
// var url = Url.Action("CaptionCategory", new {id = caption.Code} )
sb.AppendLine("<li>");
sb.AppendLine( "<a href="+ url + ">");
sb.AppendLine( caption);
sb.AppendLine( "</a>");
sb.AppendLine("</li>");
}
sb.AppendLine("</ul>");
return sb.ToString();
}
}
我需要生成与注释行中的方式类似的 url。注释代码是我在控制器类中的做法,但这是辅助类(静态上下文)。有什么帮助???
【问题讨论】:
标签: c# asp.net-mvc-2 html-helper routevalues url-action