C#语法剃刀在字符串中 [英] C# Razor Syntax inside a string
本文介绍了C#语法剃刀在字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我遇到的问题code:
This is the Code I'm having problems with:
@{int i = 1;}
@foreach (var item in Model)
{
@:<ul id="sortablei" class='droptrue'>
i++;
}
我如何用我的ID sortablei?
我想:@i或@ {I},但它不工作了我以前似乎没有空格。
所以我是一个有点无能,现在我无法找到一个答案,我在剃刀语法参考的问题。
How can I use i in the id sortablei? I tried: @i or @{i} but it seems without a space before the i its not working. I couldn't find an answer to my problem in the Razor Syntax Reference so I'm a bit clueless right now.
推荐答案
支架:
@:<ul id="sortable@(i)" class='droptrue'>
这里的括号范围剃须刀前pression;在他们不需要很多情况下,但是他们是在必要的时候:
The brackets here scope the razor expression; in many cases they aren't required, however they are necessary when:
- 除权pression(右侧)是不平凡(空格。等),需要帮助的范围之
- 其中,如果没有它,它看起来像一个电子邮件地址,即
ABC @ DEF
- 这个具有特殊处理,以避免破坏与电子邮件地址页,其中
- the expression (on the right) is non-trivial (spaces. etc) and needs help to scope it
- where without it, it looks like an email address, i.e.
abc@def
- this has special handling to avoid breaking pages with email addresses in them
这篇关于C#语法剃刀在字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文