1

异常详情:

{"A space or line break was encountered after the \"@\" character.  Only valid identifiers, keywords, comments, \"(\" and \"{\" are valid at the start of a code block and they must occur immediately following \"@\" with no space in between."}

嗨,在我的 mvc3 项目中,我在使用解码字符串值时遇到了异常

   string s="(500500) Features: • 170 GPH @ 1 ft • Operates submersed.";
   string DecodedValue = Server.HtmlDecode(Razor.Parse(s));

在此处输入图像描述

在这里它没有编码并且异常被捕获。我是如何得到解码值的。

4

1 回答 1

3

您正在尝试将以下字符串解析为 Razor 模板:

"(500500) Features: • 170 GPH @ 1 ft • Operates submersed."

在 Razor 中,该@字符表示应将以下表达式解析为 C#。如果您希望它显示为文字字符串,则需要对其进行转义:

"(500500) Features: • 170 GPH @@ 1 ft • Operates submersed."

但是,不清楚为什么需要将其解析为 Razor,因为您没有传递任何可变数据。为什么不能简单地使用以下内容?

string s="(500500) Features: • 170 GPH @ 1 ft • Operates submersed.";
string DecodedValue = Server.HtmlDecode(s);
于 2013-05-10T11:49:23.027 回答