asp.net mvc 4 - How to get select option value inside razor in mvc -
i have <select>
tag in view. example:
<html><head></head> <body> <div> <select> <option value="">select</option> <option value="alert1">alert1</option> <option value="alert2">alert2</option> </select> </div> <div id="preview"> `enter razor code here`@ { here have write condition based on <select option> tag value, need display respective viewbag. } </div> </body></html>
from controller passing viewbag
, e.g.:
viewbag.alert1="some html template1". viewbag.alert2="some html template2".
my requirement is:
on selecting <option>
, if select 'alert1', in <div id="preview">
need display viewbag.alert1
content. if user selects 'alert2' in <div id="preview">
need display viewbag.alert2
value.
i know, can use @html.raw(viewbag.alert1)
, @html.raw(viewbag.alert2)
data should displayed based on value of <select option>
tag. inside razor tag, need value of <select>
tag
something this:
@if (viewbag.alert1 != null || viewbag.alert2 != null) { @if(viewbag.alert1.selected == true) { viewbag.alert.value; } @if(viewbag.alert2.selected == true) { viewbag.alert2.value; } }
Comments
Post a Comment