how fill dropdownlist on radiobutton selection in MVC 4

Posted by Cpatil1000 under ASP.NET MVC on 9/30/2017 | Points: 10 | Views : 374 | Status : [Member] | Replies : 0
HI,
I am trying to fill dropdownlist on radiobutton selection. But I am not getting any value indropdonlist..

code :
public ActionResult GetProjectName(int ProjectID)
{
int incVal;
DataTable source;

VehicleEntity vehicleEntity;
VehicleLogic vehicleLogic;

try
{
vehicleEntity = new VehicleEntity();
vehicleLogic = new VehicleLogic();

vehicleEntity.SectionID = Convert.ToInt32(ProjectID); ;

source = new DataTable();
source = vehicleLogic.GetProjectNameData(vehicleEntity);

List<VehicleEntity> vehicleList = new List<VehicleEntity>();

for (incVal = 0; incVal < source.Rows.Count; incVal++)
{
vehicleEntity.ProjectID = Convert.ToInt32(source.Rows[incVal]["ProjectID"].ToString());
vehicleEntity.ProjectName = source.Rows[incVal]["ProjectName"].ToString();
vehicleList.Add(vehicleEntity);
}

//ViewBag.ProjectID = new SelectList(vehicleList, "ProjectID", "PROJECT_NAME", ProjectID);

//return View(ViewBag.ProjectID);

return Json(vehicleList, JsonRequestBehavior.AllowGet);

}
catch (Exception ex)
{
throw ex;
}
}

View Code :
=======
<tr>
<td style="color:maroon; font-weight:bold;">Contractor :</td>
<td style="color:maroon; font-weight:bold;">
<div class="col-md-7">
@Html.RadioButton("IRB", "1", new { id = "departmentList" }) IRB
</div>

<td colspan="2"></td>
</tr>
<tr>
<td style="color:maroon; font-weight:bold;">Project Name :</td>
<td>
<div class="col-md-12">
@Html.DropDownListFor(Model => Model.ProjectID, new SelectList(Enumerable.Empty<SelectListItem>(), "ProjectID", "PROJECT_NAME"),
new { @class = "form-control", id = "ddlProject" })
</div>
</td>
<td style="color:maroon; font-weight:bold;">Name of Toll Plaza :</td>
@*<td>@Html.DropDownList("ddlTollName", null, new { @class = "form-control" })</td>*@
</tr>

javascript :
======
@section Scripts {
<script>
function FillCity() {
var ContractorID = $('#departmentList').val();
$.ajax({
url: '/DatewiseCountReport/GetProjectName',
type: "GET",
dataType: "JSON",
data: { Project: ContractorID },
success: function (vehicleList) {
$("#ddlProject").html(""); // clear before appending new list
$.each(vehicleList, function (i, Project) {
$("#ddlProject").append(
$('<option></option>').val(vehicleList.ProjectID).html(vehicleList.ProjectName));
});
}
});
}
</script>
}




Responses

(No response found.)

Login to post response