【问题标题】:How to use special characters in url helper without encoding?如何在不编码的情况下在 url helper 中使用特殊字符?
【发布时间】:2013-04-05 15:19:13
【问题描述】:

我正在使用 ng-repeat 来显示一个中心表。对于每个中心,我想提供一个使用角度数据的编辑按钮:

       <table data-ng-init="centers" data-ng-model="Centers">
        <tr data-ng-repeat="center in centers">
            <td class="center-logo">
            </td>
            <td class="center-name">
                <h4>{{center.Name}}</h4>
            </td>
            <td class="center-address">{{center.City}}, {{center.Country}}
            </td>
            <td>{{center.StudyVersion}}</td>
            <td>
                <a href="@Url.Action("Edit","Center",new {code = {{center.Code}}})" class="btn">
                    <i class="icon-edit"></i>Edit
                </a>
            </td>
        </tr>
    </table>

现在 VS 在表达式上给我一个错误:

@Url.Action("Edit","Center",new {code = "{{center.Code}}"})

我似乎无法找到一种方法,因此 razor 使用来自 {{center.Code} 的值,就像它在纯 html 中所做的那样。

【问题讨论】:

  • 能否请您发布您从 Studio 收到的错误?
  • 在 {{center.Code} 它说表达式预期。
  • 您的声明:"似乎找不到方法,因此 razor 使用 {{center.Code} 中的值,就像在纯 html 中一样。" 是有点混乱。 Razor 是服务器端的,但我相信您使用它们时的双花括号,以及包含的值 center.code 仅对客户端的 AngularJS 有意义。

标签: razor asp.net-mvc-4 angularjs angularjs-ng-repeat


【解决方案1】:

编辑: 不需要来自初始答案的@Html.Raw()。抱歉我说得太早了。已编辑答案以反映这一点。

以下对我有用:

<a href='@Url.Action("Edit","Center")/code={{center.Code}}' class="btn">
    <i class="icon-edit"></i>Edit
</a>

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2015-10-21
    • 1970-01-01
    • 2014-09-30
    • 2023-03-20
    • 1970-01-01
    • 2022-06-27
    • 1970-01-01
    • 2014-09-17
    • 2019-03-24
    相关资源
    最近更新 更多