Skip to content

Instantly share code, notes, and snippets.

@kingbin
Created January 5, 2011 20:52
Show Gist options
  • Save kingbin/766984 to your computer and use it in GitHub Desktop.
Save kingbin/766984 to your computer and use it in GitHub Desktop.
Calling webservice and filling select tag with returned options
$(document.getElementsByName("Lic")).click(function () {
//this.checked;
//$('#ShiftID').html('<option value="TEST">TEST</option>')
$.getJSON("/ResourcePoolND/NurseRequest/UpdateShifts?Value=" + this.checked, function (data) {
$("#ShiftID").html(data);
});
});
// Codebehind
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult UpdateShifts(string Value)
{
bool lic = true;
bool.TryParse(Value, out lic);
ResourcePoolEntities resourcePoolEntities = new ResourcePoolEntities();
var shiftQuery = resourcePoolEntities.Shifts.Where(m => m.Lic == lic).Select(a => a);
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<option value=\"\">Please Select a Shift</option>");
foreach (Shift s in shiftQuery)
sb.AppendFormat("<option value=\"{0}\">{1}</option>", s.ShiftID, s.Shift1);
return Json(sb.ToString(), JsonRequestBehavior.AllowGet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment