asp.net mvc 4 - How to pass 2 parameters through $.getJson in MVC? -


i doing application in mvc. did cascading dropdownlist in list . while selecting value dropdown passed value $.getjson() controller. passing 1 id controller. problem need pass 2 id's controller. possible send 2 ids controller?

my view page

 <div>                @html.dropdownlist("business", viewbag.categoryid selectlist ,"select business category", new { id = "business" })            </div>            <div>                <label>select service type</label>                @*<select id="buname" name="buname" style="width:150px"></select>*@                @html.dropdownlist("service",  viewbag.service selectlist,"select", new { id = "service", name ="buname"})            </div>            <div>                <label> select location</label>                <select id="location" name="location" style="width:150px"></select>            </div>            <div>                <label> select location</label>                <select id="employee" name="employee" style="width:150px"></select>            </div>   <script type="text/javascript">       $(function () {            $('#business').change(function () {                $.getjson('/appt/categories/' + $('#business').val(), function (data) {                    var items = '<option> hospital</option>'                   $.each(data, function (i, service) {                       debugger;                       items += "<option value='" + service.value + "'>" + service.text +                           "</option>";                   });                    $("#service").html(items);                });             });            $('#service').change(function () {                $.getjson('/appt/location/' + $('#service').val(), function (data) {                    var items = '<option> location </option>';                   $.each(data, function (i, location) {                        items += "<option value='" + location.value + "'>" + location.text +                           "</option>";                   });                    $("#location").html(items);                });            });            $('#location').change(function () {                $.getjson('/appt/employee/' + $('#location').val(),  function (data) {                   var items = '<option> employee </option>';                   $.each(data, function (i, employee) {                        items += "<option value='" + employee.value + "'>" + employee.text +                           "</option>";                   });                    $("#employee").html(items);                   $("service").html(items);                 });           });        });       </script> 

my controller code

public actionresult waitinglist()         {             sytentities ca = new sytentities();             viewbag.categoryid = new selectlist(ca.businesscategories.tolist(), "categoryid", "categoryname");             viewbag.service = new selectlist(ca.tblbusinesscategories.tolist(), "businessid", "businessname");             return view();         }   public jsonresult categories(int id)         {             sytentities db = new sytentities();             var business = s in db.tblbusinesscategories                            s.categoryid == id                            select s;             return json(new selectlist(business.toarray(),"businessid", "businessname"), jsonrequestbehavior.allowget);         }   public jsonresult location(int id)         {               sytentities db = new sytentities();             var location = s in db.tblbusinesslocations                            s.businessid == id                             join loc in db.tbllocations                             on s.locid equals loc.locationid                            select loc;                return json(new selectlist(location.toarray(), "locationid", "locationname"), jsonrequestbehavior.allowget);          }         public jsonresult employee(int id)         {              sytentities db = new sytentities();             var emp = s in db.employees                       s.locationid == id && s.businessid == 91                       select s;             return json(new selectlist(emp.toarray(), "empid", "empname"), jsonrequestbehavior.allowget);         } 

in public jsonresult employee(int id) need pass ('#service') value. possible do? can please me?

you can pass many values want using data parameter of jquery.getjson

var url = '@url.action("categories", "appt")'; // don't hard code urls! $.getjson(url, { id: $('#business').val(), otherproperty: anothervalue }, function (data) { 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -