hELLO!
As we do use SelectedIndex Change event in asp.net for drop down list, so what is the alternate of it in MVC 4 ?
I want to provide some function calling event in drop down list selection list in mVC. (How to do that?)
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Aug 31, 2014, 11:35 PM EDT
Hi,
Jquery(html) "change" event can help you in this case...
you can write the change event for drop down either in document.ready function or with declaretion of dropdown
for example
@Html.DropDownListFor(m => m.Id, ViewData["Data"] as IEnumerable, "Select One", new {@id="changeEvent"})
Other way
@Html.DropDownListFor(m => m.Id, ViewData["Data"] as IEnumerable, "Select One", new {@id="changeEvent", onchange = "fnChangeEvent()"})
Hope this will help you.
Abhishek JaiswalRank #126 · 17.5K reputationPosted Sep 1, 2014, 12:42 AM EDT
Here's my code, in .aspx page (codebehind)
@using (Html.BeginForm("Index", "Sample", FormMethod.Post))
{
@Html.AntiForgeryToken()
Select Chart & Type
@Html.ValidationSummary()
@Html.Label("Select Chart:", new { @class = "col-md-2 control-label"})
@Html.DropDownList("Chart", ViewData["Chart"] as SelectList, new { @class = "form-control" })
@Html.Label("Select Type:", new { @class = "col-md-2 control-label" })
}
Code in my controller,
public ActionResult Index()
{
List
ListItems.Add("Select");
ListItems.Add("Area");
ListItems.Add("Line");
ListItems.Add("Column");
ListItems.Add("Pie");
SelectList Chart = new SelectList(ListItems);
ViewData["Chart"] = Chart;
return View();
}
public JsonResult Type(string Chart)
{
List
switch (Chart)
{
case "Area":
break;
case "Line":
break;
case "Column":
break;
case "Pie":
break;
}
return Json(TypeList);
}
now i want to know how to provide load of particular functions on selecting particular item from list. What i need to do to load those functions.
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 1, 2014, 1:27 AM EDT
you code look fine and it must working...
are you facing any issue?
Abhishek JaiswalRank #126 · 17.5K reputationPosted Sep 1, 2014, 4:25 AM EDT
function renderpiechart()
{
dosomething
}
and more..
now i want to know how to access them in my click event of dropdown list.
like if i selected column chart then it must render column chart and so on.
what event i need to create for that functionality
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 1, 2014, 8:14 PM EDT
drop down change event can help you because it give the guaranty to data change