下面我提到了我们从数据库获取dropdownlist值的代码,但是我收到了错误。错误意味着在角度代码中不调用angular http方法url everthing所以dropdown显示为空。
AngularJS
$scope.product = function (e) {
$http({
method: "GET",
url: "/Prescription/GeneratePrescriptions"
}).
then(function (response) {
$scope.formulationlist = response.data;
}, function () {
alert("Error Occur");
})
}
Controller
public ActionResult GeneratePrescriptions()
{
FDAGeneric_Bind();
FDAFormulation_Bind();
TestFDAFormulation_Bind();
return View();
}
public JsonResult TestFDAFormulation_Bind()
{
DataSet ds = dFDA.Get_FDAFormulation();
List<SelectListItem> Formulationlist = new List<SelectListItem>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
Formulationlist.Add(new SelectListItem { Text = dr["Formulation"].ToString(), Value = dr["FormulationID"].ToString() });
}
//ViewBag.MasterFormulationID = Formulationlist;
return Json(Formulationlist, JsonRequestBehavior.AllowGet);
}
View
<td>
<select ng-model="r.formulationid" ng-change="" ng-options=" p.formulationid as p.formulation for p in formulationlist" class="form-control">
<option value="">Select Product</option>
</select>
</td>