如何在 MVC 3 razor 中使用文本标签 [英] 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中使用text标签的方式和规则是什么
i not want to put @@ instead of @ on every pattern. well what is the way and rule for using text tag in MVC
推荐答案
当您将某些内容包装在文本标签中时,您是在对 Razor 说这是文本"而不是代码.如果你想要代码,你可以做一个代码块,如:
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>
如果您在某种循环中执行此操作,则可以继续编写代码:
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;
}
在上面的例子中,razor 知道什么是代码,什么不是.如果您想将标记放入循环中,则可以扩展上面的示例:
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>
}
您只需要在没有任何 html 标签的循环内使用
标签即可.
You only really need to use the <text></text>
tags inside of loops where you don't have any html tags.
Razor 足够智能,因此当您在循环中打开标签时,例如<p>
它知道,直到该标签关闭,然后它在标记中.当它关闭时,它将寻找一个 }
来关闭一个循环(或另一个 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 razor 中使用文本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!