// This code is for two dropdownlist but it is not working. i want the code for four dropdownlist
//This is my Home controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
RTC_PRINT_XMLEntities db = new RTC_PRINT_XMLEntities();
ViewBag.District = new SelectList(db.RTC_XML_ADT, "ADT_DIST_CODE", "ADP_DIST_NAME");
return View(); }
public JsonResult GetTalukById(string ID)
{
List taluk = new List();
var talukList = this.Gettaluk(Convert.ToInt32(ID));
var talukData = talukList.Select(m => new SelectListItem()
{
Text = m.ADT_TALUK_NAME,
Value = m.ADT_TALUK_CODE.ToString(),
});
return Json(talukData, JsonRequestBehavior.AllowGet);
}
public IList Gettaluk(int ADT_DIST_ID)
{
RTC_PRINT_XMLEntities db = new RTC_PRINT_XMLEntities();
return db.RTC_XML_ADT.Where(m => m.ADT_DIST_CODE == ADT_DIST_ID).ToList();
}
[HttpPost]
public ActionResult Index(FormCollection formdata)
{
Get Employee information to insert into Data Base
return RedirectToAction("Index", "Home");
}
}
}
This is my Index view
@using (Html.BeginForm("Fetch details", " Home ", FormMethod.Post))
{
@Html.LabelFor(model => model.ADT_DIST_CODE)
@Html.DropDownListFor(model => model.ADT_DIST_CODE, ViewBag.District as SelectList, "Select District", new { id = "ADT_DIST_CODE" })
@Html.LabelFor(model => model.ADT_TALUK_CODE)
@Html.DropDownListFor(model => model.ADT_TALUK_CODE, new SelectList(string.Empty, "Value", "Text"), " Select Taluk ",
new { style = "width:250px", @class = "dropdown1" })
@*
$(document).ready(function () {
//Country Dropdown Selectedchange event
$("#RTC_XML_ADT").change(function () {
$("#RTC_XML_ADT").empty();
$.ajax({
type: 'POST',
url: '@Url.Action("GetTalukById")', // Calling json method
dataType: 'json',
data: { id: $("#RTC_XML_ADT").val() },
// Get Selected Country ID.
success: function (taluk) {
$.each(taluk, function (i, takuks) {
$("##RTC_XML_ADT").append('
taluks.Text + '');
});
},
error: function (ex) {
alert('Failed to retrieve states.' + ex);
}
});
return false;
})
});
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manas MohapatraPosted Dec 23, 2016, 1:58 AM
imran bhattiPosted Dec 23, 2016, 6:24 AM
imran bhattiPosted Dec 23, 2016, 1:35 AM
Manas MohapatraPosted Dec 22, 2016, 1:08 PM