3

@homePartnership.Batsman1Runs is the dynamic value from an api and px is static, if it runs next to each other, it breaks as @homePartnership.Batsman1Runspx isnt a valid field and if there is a space, html wont follow the width, below is what I currently have, it does not work.

<div class="left-bar" style="width:@homePartnership.Batsman1Runs{<text>px</text>}"></div>

1 Answer 1

4

Surround the dynamic part with parentheses (the @( ... ) construct):

<div class="left-bar" style="width:@(homePartnership.Batsman1Runs)px"></div>

Note that Razor parses on whitespace, so this is valid Razor syntax: "width: @homePartnership.Batsman1Runs px". But of course, that produces "width: 5 px", which isn't quite valid CSS. However, as above, you can always add the parentheses to delineate a code block.

For reference, inline Razor Syntax:

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.