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.
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.
Jignesh TrivediPosted Sep 2, 2014, 12:14 AM
drop down change event can help you because it give the guaranty to data change
Abhishek JaiswalPosted Sep 1, 2014, 8:25 AM
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 TrivediPosted Sep 1, 2014, 5:27 AM
you code look fine and it must working...
are you facing any issue?
Abhishek JaiswalPosted Sep 1, 2014, 4:42 AM
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 TrivediPosted Sep 1, 2014, 3:35 AM
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.