none
Razor selected attribute as string for the attribute in the option tag RRS feed

  • General discussion

  • Hello,

    var valueId = value.Id;
    var valueName = value.Name;
    var isSelected = property.CurrentValue.Id == valueId ? "selected" : "none";

    <option id="@valueId" value="@valueName" selected="@isSelected">@valueName</option>

    @isSelected works fine, while @selected, as the variable name, shows the warning.

    Thank you,

    Denis

    • Moved by Sabah ShariqMVP Wednesday, March 7, 2018 5:57 AM Moved from Visual C#
    Tuesday, March 6, 2018 7:37 PM

All replies

  • @isSelected works fine, while @selected, as the variable name, shows the warning.

    Then I suggest that you don't use it.

    The issues and can be discussed at the MVC forum.

    http://forums.asp.net/

    Tuesday, March 6, 2018 10:06 PM