John x
John x

Reputation: 4031

Ternary condition using Razor

I am using the star rating plugin and i want to set the value of data-rateit-readonly based on certain condition i.e

  data-rateit-readonly="@Request.IsAuthenticated?(@Model.HasRatedOnAccuracy?true:false):true"

but it gives me

data-rateit-readonly="True?(False?true:false):true"

but i want if the Request id authenticated then it should check whether the user has already rated or not at the end the final html should look like either

data-rateit-readonly="true"

or

data-rateit-readonly="false"

please help me solve this problem...

Upvotes: 0

Views: 116

Answers (1)

Justin Niessner
Justin Niessner

Reputation: 245499

You should use the multi-token syntax support (broken apart for readability):

data-rateit-readonly="@(Request.IsAuthenticated ? (
    Model.HasRatedOnAccuracy ? true : false
) : true)"

Upvotes: 2

Related Questions