Reputation: 1275
I have 2 if statements that use a ViewBag value that ties it down to a dropdownlist how if a user changes the ViewBag Value can I detect it with Jquery for instance I have...
@Html.DropDownList("MyValue", new SelectList(
new List<Object>{
new{ Text = "10", Value= 10},
new{ Text = "30", Value= 30}}, "Value", "Text"))
@if (ViewBag.MyValue == 10)
{
// value is 10
}
@if (ViewBag.MyValue == 30)
{
// my value is 30
}
As you can see I have a dropdownlist with the I.D. MyValue is there some way that i can get Jquery to do something like
**MyValue.change
{
if (MyValue== 30)
{
// display ViewBag.MyValue== 30
}
}**
Upvotes: 0
Views: 1413
Reputation: 29186
Try something like:
$("#MyValue").change(function() {
console.log($(this).val());
});
Upvotes: 2