c# - strange error in razor -


i have this:

<tr class="@(item.id == (int)(session["id"] ?? 0) ?     "sfs-selected sfs-selectable" : string.empty)"> 

but meesage:

operator '==' cannot applied operands of type 'method group' , 'int' 

but cast int.

if this:

 <tr class="@if (item.id == (string)(session["id"] )) {@("sfs-selected sfs-selectable") } @string.empty "> 

then error:

unable cast object of type 'system.int32' type 'system.string'. 

so how check on null value?

thank you

if this:

 <tr class="@(item.id == (session["id"] ?? 0) ? "sfs-selected sfs-selectable" : string.empty)"> 

i warning:

warning error: possible unintended reference comparison; value comparison, cast right hand side type 'string'

so this:

<tr class="@(item.id == (string)(session["id"] ?? 0) ? "sfs-selected sfs-selectable" : string.empty)"> 

then this:

unable cast object of type 'system.int32' type 'system.string'. 

you should either remove (int) type cast or make id int. see fiddle.

https://dotnetfiddle.net/1lmstm // showing error

https://dotnetfiddle.net/ka4y59 // changing id int string

https://dotnetfiddle.net/lhsim3 // removing int type cast id string


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -