美元符号和/或短跑打破Razor的解析器 [英] Dollar sign and/or Dash breaking Razor's parser

查看:105
本文介绍了美元符号和/或短跑打破Razor的解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

落脚点我试图渲染:

<input type="radio" name="options" id="options_1" />$1 - A Not Very Expensive Chocolate
<input type="radio" name="options" id="options_2" />$10 - A Kinda Expensive Chocolate
<input type="radio" name="options" id="options_3" />$100 - A Really Expensive Chocolate

从这个code:

From this code:

@foreach (var o in Model.Options){
    <input type="radio" name="options" id=@("options_" + @o.ID) />$@o.PriceToAdd - @o.Label
}

如果我放弃这两个$和 - 从什么应该是普通的文本 - 东西的作品。无论是增加导致编译警告和运行时错误。我试过<一个href=\"http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx\"相对=nofollow>这里描述,但还没有找到正确的组合还没有明确的语法。

If i drop both the '$' and the '-' from what should be plain old text - stuff works. Adding either resulted in compiler warnings and runtime errors. I've tried the explicit syntax as described here but haven't found the right combination yet.

推荐答案

尝试这样的:

<击>

@foreach (var o in Model.Options) {
    <input type="radio" name="options" id=@("options_" + @o.ID) />
    <text>$</text>@o.PriceToAdd - @o.Label
}

或:

@foreach (var o in Model.Options) {
    <input type="radio" name="options" id=@("options_" + @o.ID) />
    @:$@o.PriceToAdd - @o.Label
}

@foreach (var o in Model.Options) {
    <input type="radio" name="options" id=@("options_" + @o.ID) />
    @MvcHtmlString.Create("$")@o.PriceToAdd - @o.Label
}

PriceToAdd 是一个数字:

@foreach (var o in Model.Options) {
    <input type="radio" name="options" id=@("options_" + @o.ID) />
    @o.PriceToAdd.ToString("c") - @o.Label
}

这篇关于美元符号和/或短跑打破Razor的解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆