2

How do I concatenate my Razor variables? This is what I have:

@foreach (var item in ViewBag.Pcs) {
    <li><a href="#" class="btn"><i class="icon-hdd"></i>
    @item.Manufacturer.ManufacturerName + ' ' + @item.HardwareType.HType </a></li>
}

But it's showing the quote marks and the pluses. How do I put a space between my two Razor variables?

2
  • Just leave a space? or use &nbsp Commented Dec 28, 2012 at 16:49
  • Why didn't I think of that. Razor is smarter than PHP. Thanks, Forty-Two. Commented Dec 28, 2012 at 16:50

1 Answer 1

1

You just need to leave a space between the variables, for example:

@foreach (var item in ViewBag.Pcs) {
   <li><a href="#" class="btn"><i class="icon-hdd"></i>
  @item.Manufacturer.ManufacturerName @item.HardwareType.HType </a></li>
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.