Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
Asp.net mvc 在ASP.NET MVC RC3中,使用Razor-@String.Format(“{0:hh:mm:ss}”,timespan)错误-错误?_Asp.net Mvc_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net mvc 在ASP.NET MVC RC3中,使用Razor-@String.Format(“{0:hh:mm:ss}”,timespan)错误-错误?

Asp.net mvc 在ASP.NET MVC RC3中,使用Razor-@String.Format(“{0:hh:mm:ss}”,timespan)错误-错误?,asp.net-mvc,asp.net-mvc-3,razor,Asp.net Mvc,Asp.net Mvc 3,Razor,以下错误包含FormatException: <td class="numeric">@String.Format("{0:hh:mm:ss}", testrun.ExecutionTime)</td> @String.Format(“{0:hh:mm:ss}”,testrun.ExecutionTime) 其中ExecutionTime是一个时间跨度。此格式字符串有效。这是一个bug还是我遗漏了一些明显的东西(考虑到时间已经很晚了——后者可能就是它) 尝试转义: S

以下错误包含FormatException:

<td class="numeric">@String.Format("{0:hh:mm:ss}", testrun.ExecutionTime)</td>
@String.Format(“{0:hh:mm:ss}”,testrun.ExecutionTime)

其中
ExecutionTime
是一个时间跨度。此格式字符串有效。这是一个bug还是我遗漏了一些明显的东西(考虑到时间已经很晚了——后者可能就是它)

尝试转义

String.Format("{0:hh\\:mm\\:ss}", testrun.ExecutionTime)

您不是在寻找
@testRun.ExecutionTime.ToString(“此处格式化”)
方法吗


设置timespan的字符串格式:

你不是在那里转义反斜杠吗?@jgauffin,不,你转义
,这在
字符串格式中被认为是一个特殊字符。或者,如果需要单个反斜杠,可以:
String.Format(@“{0:hh\:mm\:ss}”,testrun.ExecutionTime)
。这是标准的C#,与MVC或razor无关。我原以为
\n
会产生换行符,但
\\n
会产生一个带反斜杠和“n”的字符串。@jgauffin是这样做的,但他想在字符串中插入反斜杠,以便格式分析器知道他必须转义:(:是.NET格式字符串中的特殊字符)。single\是编译器转义字符,因此他必须转义转义字符,使其通过编译器并进入格式字符串解析器。这在.NET 4.0中是新的。看起来像是一个耀眼的使命。谢谢。嘿,即使是这种方法也需要“hh\\:mm\\:ss”。