Click here to Skip to main content
15,888,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually I have the data in @html.dropdown("data"),"the data is having the all cities " ,now I wanna call the controller function with the OnChange event of this dropdown.Can u plz help to do this ...thanks in advance.

What I have tried:

View:
    ViewBag.Title = "cities";
}
@using (Html.BeginForm("cities", "Home", FormMethod.Get))
{
   
       @Html.DropDownList("cities", null, new { @onchange = "location = this.value;" })

           }


Controller:
ublic class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

//
I wanna call this function with onchange event
public List<Tuple<string, int, int>>gethillstatoins (List<string> hillstations)
        {
		////
		////
		////
		
		}

Script:

function gethillstatoins() {
      jQuery.ajax({
            url: '@Url.Action("Action Method Name", "Controller Name")',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify({ data: data2 }),
            success: function (result) { }
        });  
Posted
Comments
F-ES Sitecore 1-Mar-18 5:05am    
Doesn't this work

@Html.DropDownList("cities", null, new { @onchange = "gethillstatoins();" })
SureshMunna 1-Mar-18 5:22am    
tq for ur response, I have changed my code as u suggested but the controller function is not invoking while debugging.

Actullay I wanna call the ajax call next with the help of url in ajax I wanna invoke the controller function.
Karthik_Mahalingam 21-Mar-18 23:52pm    
Tip: use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
Richard Deeming 1-Mar-18 12:40pm    
url: '@Url.Action("Action Method Name", "Controller Name")',

Is that literally what your code says, or have you replaced the "Action Method Name" and "Controller Name" placeholders with the correct action and controller names?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900