Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Html.ActionLink标题参数作为测试+;价值_C#_Asp.net Mvc 3_Html.actionlink - Fatal编程技术网

C# Html.ActionLink标题参数作为测试+;价值

C# Html.ActionLink标题参数作为测试+;价值,c#,asp.net-mvc-3,html.actionlink,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>
    <%: Html.ActionLink("TUK-JS-KPI-WE-" + ((DateTime)Eval(ViewBag.jobSortedReportDate)).ToString("yyyy-MM-dd"), "TradeUKKPIReportInstructions", "Report", new { @date = ViewBag.jobSortedReportDate }, 0)%>    
 </p>


如何将文本添加到值?

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

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

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

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

您也可以试试这个

<%: 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>


是的,谢谢,刚刚发现,但再次出现错误,无法将类型DateTime转换为字符串..让我快速查看:)在这种情况下,将其转换为日期时间而不是字符串
(DateTime)ViewBag.jobSortedReportDate
是正确的,很抱歉今天有点慢,熬夜学习:)我想进一步了解这一点:但显然这是不正确的,你应该阅读更多关于转换和类型转换的内容;)<代码>((DateTime)ViewBag.jobSortedReportDate).ToString(“yyyy MM dd”)是的,谢谢你,刚刚发现了,但又出现了一个错误,无法将类型DateTime转换为字符串。让我快速看一下:)在这种情况下,将其转换为日期时间,而不是字符串
(DateTime)ViewBag.jobSortedReportDate
是的,很抱歉今天有点慢,熬夜学习:)我想进一步了解这一点:但显然这是不正确的,你应该阅读更多关于转换和类型转换的内容;)<代码>((DateTime)ViewBag.jobSortedReportDate).ToString(“yyyy-MM-dd”)oops我忘记了System.Format,但仍然得到错误:“System.Web.Mvc.HtmlHelper”没有名为“ActionLink”的适用方法,但似乎有一个名为“ActionLink”的扩展方法。无法动态调度扩展方法。考虑在不使用扩展方法语法的情况下强制转换动态参数或调用扩展方法。我必须添加:我的行在view.aspx中。您需要在String.Format中强制转换为DateTime,以使其与ViewBag
String.Format(“TUK-JS-KPI-WE-{0}”,(DateTime)ViewBag.jobSortedReportDate)
谢谢+祝你好运。我将它与
ViewBag.Title
一起使用,认为这是一个字符串。现在我知道我忘记了System.Format,但仍然得到错误:“System.Web.Mvc.HtmlHelper”没有名为“ActionLink”的适用方法,但似乎有一个名为“ActionLink”的扩展方法。无法动态调度扩展方法。考虑在不使用扩展方法语法的情况下强制转换动态参数或调用扩展方法。我必须添加:我的行在view.aspx中。您需要在String.Format中强制转换为DateTime,以使其与ViewBag
String.Format(“TUK-JS-KPI-WE-{0}”,(DateTime)ViewBag.jobSortedReportDate)
谢谢+祝你好运。我将它与
ViewBag.Title
一起使用,认为这是一个字符串。现在我更清楚了