Click here to Skip to main content
16,016,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
How to pass this into my view , how can i show this result as dropdown list.

Thanks!

What I have tried:

in my controller i have generated drop down like this

[HttpPost]
public ActionResult getCicites(int provinceId)
{
     var cities = db.cities.Where(a => a.provinceId == provinceId).Select(a => "<option value='" + a.cityId + "'>" + a.cityName + "'</option>'";

     return Content(String.Join("", cities));
}
Posted
Updated 9-Mar-17 23:45pm

1 solution

Html
<select id="ddl"></select>

Javascript
var id = 1;  // Your id
       $.ajax({
           type: "POST",
           url: '@Url.Action("getCicites", "YourControllerName")',
           data: { provinceId: id},
           success: function (d) {
               $('#ddl').append(d);
           }
       });
 
Share this answer
 
v2
Comments
T_Sub 10-Mar-17 5:48am    
Thank you very much its working !!
Karthik_Mahalingam 10-Mar-17 5:50am    
welcome :)

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