I have the following code:
@Html.DropDownList("jenisBarang", new SelectList(ViewBag.listJenis), "Pilih Perangkat/Layanan", new { @class = "form-control", @id = "ddlJenis", @onchange = "GetMerk(this.value);", @name="jenisBarang" })
@Html.DropDownList("merkBarang", new SelectList("pilih Merk"), "Pilih Merk", new { @class = "form-control", @id = "ddlMerk", @name = "jenisBarang" })
The second Dropdownlist consists of some strings based on what I've chosen from the first dropdownlist.
ex:
- a
- b
- c
When I send it to my action, it read as integer (0).
How do I get the value of the dropdownlist as a string? (ex I chose a)
edit: this is the code to manipulate the second dropdown:
<script language="javascript" type="text/javascript">
function GetMerk(_jenis) {
var procemessage = "<option value='0'> Please wait...</option>";
$("#ddlMerk").html(procemessage).show();
var url = "/Barang/GetMerkByJenis/";
$.ajax({
url: url,
data: { jenisID: _jenis },
cache: false,
type: "POST",
success: function (data) {
var markup = "<option value='0'>Select Merk</option>";
for (var x = 0; x < data.length; x++) {
markup += "<option value=" + x + ">" + data[x]+ "</option>";
}
$("#ddlMerk").html(markup).show();
},
error: function (reponse) {
alert("error : " + reponse);
}
});
}
</script>
dataValueField) with column name which represents value passed from DDL.