user1765862
user1765862

Reputation: 14155

passing multiple informations in anonymous object using razor helper

If I'm already assigning value using anonymous object inside html element using razor helper

@Html.ReadOnlyTextBox(MyObject.SomeId.ToString(), MyObject.PersonName.ToString(), true, new { @class = field.IsWarned ? "myCssClassName" : string.Empty })

now I want to extend this above code

var someVar = true;
if(a>b){
   someVar = false;
}

how can I inject also value of someVar together with @class (in both cases)

Upvotes: 0

Views: 125

Answers (1)

user1672994
user1672994

Reputation: 10849

If you want to pass the parameter to html attributes you can pass it as another parameter

Html.ReadOnlyTextBox(MyObject.SomeId.ToString(), MyObject.PersonName.ToString(), true, new { @class = (field.IsWarned ? "myCssClassName" : string.Empty), @someVar = (a > b ? false: true) })

Upvotes: 1

Related Questions