1

I need to generate a string which looks like variable, dot, space, another variable.

The @Model.Number. @Model.Task or @(Model.Number). @(Model.Task) or @{Model.Number}. @{Model.Task} doesn't seem to compile.

The @Model.Number<text>. </text>@Model.Task works, but it generates a trashy <text> tag in the resulting html.

If I place all of these on a separate line:

@Model.Number
. 
@Model.Task

then the result will render with an extra space between the number and the dot.

The @Model.Number@:. @Model.Task doesn't compile either.

Peret Finctor
  • 192
  • 1
  • 7
  • 3
    `@string.Format("{0}. {1}", Model.Number, Model.Task)` –  Nov 22 '15 at 13:01
  • 1
    Possible duplicate of [Displaying a literal period following razor syntax](http://stackoverflow.com/questions/16651584/displaying-a-literal-period-following-razor-syntax) – DavidG Nov 22 '15 at 13:07
  • `@(Model.Number). @Model.Task` does work for me (MVC 5 Razor 3) – haim770 Nov 22 '15 at 13:09
  • @haim770 Disregard what I said about @() not working, I was just lazy to try everything blindly, sorry. It works, thanks! – Peret Finctor Nov 22 '15 at 13:13
  • 1
    @PeretFinctor Then you should accept this question is a duplicate. – DavidG Nov 22 '15 at 14:18

2 Answers2

0

Try this:

@(Model.Number). @Model.Task
haim770
  • 48,394
  • 7
  • 105
  • 133
0

Another solution:

@(Model.Number + ". " + Model.Task)
ZippyV
  • 12,540
  • 3
  • 37
  • 52