如何使用MVC 3剃须刀文本标签 [英] how to use text tag in MVC 3 razor
问题描述
我想在MVC 3页我有意见使用正则表达式。我怎么可以用
i want to use regex on the views i have in MVC 3 page. how i can use
当我用文字标签包装他们,他们无法正常工作例如:
when i wrap them with text tag they not work ex:
<text> var pattern = @fjkfdkl</text>
我不希望把@@代替@每一个模式。还有什么是使用MVC文本标记的方式和规则
i not want to put @@ instead of @ on every pattern. well what is the way and rule for using text tag in MVC
推荐答案
当你包在一个文本标签的东西你都这么说剃刀这是文不是code。如果你想code你可以再做像code座:
When you wrap something in a text tag your are saying to Razor that "this is text" not code. If you want code you can then do a code block like:
<text>@{ var pattern = fjkfdkl; }</text>
如果您在某种循环你可以继续编写code的这样:
If you are doing this in some sort of loop you can just continue writing your code:
foreach(var o in listOfObjects) {
var pattern = fjkfdkl;
}
在上面的例子中剃刀知道什么code,哪些不是。然后,您可以在上面的例子中,如果扩展要放置标记的循环:
In the above example razor knows whats code and what is not. You can then expand on the above example if you want to put markup in the loop:
foreach(var o in listOfObjects) {
var pattern = fjkfdkl;
<text>
Hello World!
</text>
}
或
foreach(var o in listOfObjects) {
var pattern = fjkfdkl;
<p>
Hello World.
<p>
}
您只有真正需要使用&LT;文本&GT;&LT; /文本方式&gt;环内
标签,你没有任何HTML标记
You only really need to use the <text></text>
tags inside of loops where you don't have any html tags.
剃刀足够聪明,所以当你打开你的标签的循环中例如&LT; P&GT;
它知道,直到该标记已关闭,则其标记。当它被关闭它就会寻找一个}
为一个循环的结束(或其他HTML标记)。
Razor is smart enough so when you open your tag inside a loop e.g. <p>
it know until that tag is closed then its in markup. When it is closed it will then look for a }
for the closing of a loop (or another html tag).
这篇关于如何使用MVC 3剃须刀文本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!