I have a drop down list populated with Ajax call, now i have to select populated value and store it in database table in controller action method. I go through these two answers on stack overflow link1, link2 and try provided solution but it not works.
Action method:
public ActionResult ClassCreated(Class c)
{
c.Course.title = Request.[""];
c.ClassName=Request["ClassName"];
c.strength = Int16.Parse(Request["strength"]);
c.rollNoPattern = Request["rollNoPattern"];
db.Classes.Add(c);
db.SaveChanges();
return RedirectToAction("Index");
}
Jquery:
<script>
$(document).ready(function () {
$('#b1').click(function () {
var userName = "Hello"
$.getJSON("/classes/getCourseList?username=" + userName, function (data1) {
var myOptions =
{
val1: data1.title
};
var $mySelect = $('#s1');
$.each(myOptions, function (val, text) {
$mySelect.append($('<option />',
{
value: val,
text: text
}));
});
});
});
});
</script>