Jquery
<script>
function save() {
var cval;
var str = "";
$(".chkmaincat:checked").each(function (i) {
cval = $(this).val();
str = str + cval + ",";
});
alert(str);
var source =
{
'Name': $('#Name').val(),
'Code': $('#Code').val(),
'Address': $('#Address').val(),
'City': +$('#City').val(),
'State': $('#State').val(),
'City': $('#City').val(),
'Country': $('#Country').val(),
'Phone': $('#Phone').val(),
'Fax': $('#Fax').val()
}
$.ajax({
type: "POST",
url: '/Hospitals/Save?st='+str,
data: source
});
}
</script></script>
Controller
public ActionResult Save(string st,Hospital hospital)
{
if (ModelState.IsValid)
{
db.Hospitals.Add(hospital);
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
var dept = db.Departments.ToList();
ViewBag.department = dept;
}
return View(hospital);
}
By doing the above i got the string value as well as the modal.Thank you everyone for the help.