我有一个用作ViewModel的类'IncomeStatement‘。这个类有一个属性,可以生成一些相当复杂的html,如下所示:
public MvcHtmlString HtmlPeriods { get; set; }
....
StringBuilder htmlPeriods = new StringBuilder(100);
htmlPeriods.AppendFormat(
"<td><a href='/Forecast/IndexPeriod?Period={1}'>{0}</a></td>",
inc.NetSales, per.Period.PeriodID);
....
HtmlPeriods = MvcHtmlString.Create(htmlPeriods.ToString())
然后在Razor文件中,我使用了HtmlPeriods属性,它工作得很好:
<th></th>@Model.HtmlPeriods<td></td>
但是如果我想使用Html.ActionLink(...)在我的类中创建
像剃刀一样漂亮的链接,就像这样:
string forecastLink =
Html.ActionLink("Edit Forecast", "/Forecast/IndexEdit?PeriodID=2005Q1");
我该怎么做呢?
发布于 2011-08-01 21:57:53
您可以使用HtmlHelper类来完成此操作。我认为您会需要GenerateLink方法。
示例:
string link = HtmlHelper.GenerateLink(HttpContext.Current.Request.RequestContext, System.Web.Routing.RouteTable.Routes, "My link", "Default", "Index", "Home", null, null);
https://stackoverflow.com/questions/6897041
复制相似问题