DevSoft0
DevSoft0

Reputation: 37

Asp.Net Remove space beteen model property and text

(Asp.Net) I'm keeping css properties in database table but when I want to display them in view like this:

style="margin-top: @Model.Settings.MarginTop px;"

I have a problem with space between value and px.

Yes I know I can add "px" inside get or write something like this below but I'm sure there is simple way.

style="margin: @Html.Encode(Model.Settings.MarginTop)px"

Upvotes: 2

Views: 412

Answers (2)

heathesh
heathesh

Reputation: 1041

You should also be able to use string.Format:

style="margin-top:@string.Format("{0}px", Model.Settings.MarginTop)"

Upvotes: 1

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

Try using @() as shown :-

style="margin-top: @(Model.Settings.MarginTop)px;"

Upvotes: 2

Related Questions