Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...