我的视图页面中有以下控件。如何以非常简单的方式处理选定的更改事件?
@{
List<SelectListItem> invoiceTypes= new List<SelectListItem>();
invoiceTypes.Add(new SelectListItem
{
Text = "--Select One--",
Value = "",
Selected = true
});
invoiceTypes.Add(new SelectListItem
{
Text = "Form 8",
Value = "Form 8"
});
invoiceTypes.Add(new SelectListItem
{
Text = "Form 8B",
Value = "Form 8B"
});
invoiceTypes.Add(new SelectListItem
{
Text = "eBay",
Value = "eBay"
});
invoiceTypes.Add(new SelectListItem
{
Text = "Snapdeal",
Value = "Snapdeal"
});
}
@Html.DropDownListFor(model => model.InvoiceType, invoiceTypes, new { @class = "dropdownlist"})
答案 0 :(得分:1)
Html.DropDownListFor
将呈现为select
,如
<select class="dropdownlist">
<option value="">--Select One--</option>
<option value="eBay">eBay</option>
<option value="Snapdeal">Snapdeal</option>
</select>
您可以处理change
事件,例如
$(".dropdownlist").change(function () {
alert(this.value);
});
答案 1 :(得分:0)
You can use OnChange Event of Jquery since its same as normal HTML Control:
$(.dropdownlist).change(function()
{
// Write your code here..
}
);
希望这会有所帮助..