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:*************">&nbsp;&nbsp;&nbsp;</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)">&nbsp;&nbsp;&nbsp;</div> 

you can't call js function style attribute, line

<div style="background-color:inttocolorhex(@item.colorcode)">&nbsp;&nbsp;&nbsp;</div> 

just render

<div style="background-color:inttocolorhex(100000)">&nbsp;&nbsp;&nbsp;</div> 

but can use simple tostring hexadecimal ("x") format specifier like

<div style="background-color:#@item.colorcode.tostring("x6")">&nbsp;&nbsp;&nbsp;</div> 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -