Home > Net >  What to use in a Razor Inline express when you have to attach another fixed string
What to use in a Razor Inline express when you have to attach another fixed string

Time:10-04

What is the best practice when you have to use a razor variable but you cannot have a space after it ?

eg.

@foreach (var photo in Model.Photos)
{
        <a style="width:@photo.ThumbWidth px;" href="..."><img....></a>
}

I don't want the space before "px"

  • a method in the Model class that build the string ?
  • String.Concat ?
  • String interpolation with $ ?

Thanks

CodePudding user response:

Parentheses:

@foreach (var photo in Model.Photos) {
        <a style="width:@(photo.ThumbWidth)px;" href="..."><img....></a> 
}
  • Related