Reputation: 14155
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
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