How to set the value of a select element's selected property

I am using webmatrix, razor syntax and cshtml file.

I have an "edit" page for a database record which contains a select box(id="selStatus"). I am trying to set the "selected" value of the select box dynamically, based on the value of the current record being edited.

I have the current value or its index in local var's but i cant seem to assign this value back to the select.

if (currentStatus=="Completed"){
    selStatus.options[1].selected=true;
}

RES = error: The name 'selStatus' does not exist in the current context.

I am missing something obvious here but can't seem to get it. Any ideas appreciated. Thanks

12
задан Peter Hall 16 April 2017 в 03:13
поделиться