Html.ActionLink Title参数作为test + value

时间:2012-08-21 07:13:26

标签: c# asp.net-mvc-3 html.actionlink

我有这条线但不确定+字符串部分。它现在不正确:

 <p>
    <%: Html.ActionLink("TUK-JS-KPI-WE-" + ((DateTime)Eval(ViewBag.jobSortedReportDate)).ToString("yyyy-MM-dd"), "TradeUKKPIReportInstructions", "Report", new { @date = ViewBag.jobSortedReportDate }, 0)%>    
 </p>

如何将文字添加到值?

2 个答案:

答案 0 :(得分:3)

如果jobSortedReportDate包含字符串值,则应将其强制转换为字符串,如下所示:

<%: Html.ActionLink("TUK-JS-KPI-WE-" + (string)ViewBag.jobSortedReportDate, "TradeUKKPIReportInstructions", "Report", new { @date = ViewBag.jobSortedReportDate }, 0)%> 

答案 1 :(得分:0)

你也可以尝试这个

<%: Html.ActionLink(String.Format("TUK-JS-KPI-WE-{0}", (DateTime) ViewBag.jobSortedReportDate), "TradeUKKPIReportInstructions", "Report", new { @date = ViewBag.jobSortedReportDate }, 0)%>

这是替代

<a href="@Url.Action("TradeUKKPIReportInstructions", new {Controller = "Report", @date = ViewBag.jobSortedReportDate })">@String.Format("TUK-JS-KPI-WE-{0}", ViewBag.jobSortedReportDate )</a>