I'm was trying to fill in a description field when a drop-down was selected. I Got it working but I couldn't use a Json Content Type. This works
<script type="text/javascript">
$(document).ready(function () {
$("#ddl_id").change(function () {
var test = $("#ddl_id").val();
$.ajax({
type: "POST",
url: "<%= Url.Action("GetVal") %>",
data: {id: test},
//contentType: "text/plain",
dataType: "json",
success: function(result) {
$("#serial").val(result);
},
error: function(e) {
alert(e);
}
});
});
});
</script>
But when I uncomment the contentType: I get null returned to my controller. I've also tried
contentType: "application/json; charset=utf-8",
This is my controller
[HttpPost]
public JsonResult GetVal(string id)
{.......
Why is it that when I have a contentType I get null passed? And what is the best way to encode Json data? I'm totally new at this and I couldn't find a straight forward explanation.