Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

html - how to use text tag in MVC 3 razor

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>

i not want to put @@ instead of @ on every pattern. well what is the way and rule for using text tag in MVC

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
}

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>
}

or

foreach(var o in listOfObjects) {
  var pattern = fjkfdkl;
  <p>
    Hello World.
  <p>
}

You only really need to use the <text></text> tags inside of loops where you don't have any html tags.

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...