Created
January 5, 2011 20:52
-
-
Save kingbin/766984 to your computer and use it in GitHub Desktop.
Calling webservice and filling select tag with returned options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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