asp.net mvc - convert model property value with javascript in razor -
i have foreach iterate through items in razor syntax,
@foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.name) </td> <td> @html.displayfor(modelitem => item.colorcode) </td> <td> <div style="background-color:*************"> </div> </td> <td> @html.actionlink("edit", "edit", new { id = item.id }) | @html.actionlink("details", "details", new { id = item.id }) | @html.actionlink("delete", "delete", new { id = item.id }) </td> </tr> }
colorcode int value ,i define external function named inttocolorhex convert colorcode equivalent hex value,i want replace ************** hex color value each row according colorcode,i need thing bellow:
<div style="background-color:inttocolorhex(@item.colorcode)"> </div>
you can't call js function style attribute, line
<div style="background-color:inttocolorhex(@item.colorcode)"> </div>
just render
<div style="background-color:inttocolorhex(100000)"> </div>
but can use simple tostring hexadecimal ("x") format specifier like
<div style="background-color:#@item.colorcode.tostring("x6")"> </div>
Comments
Post a Comment