Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery dropdownlist from mvc jsonresult list

// mvc
 List<SelectListItem> corgCodeLst = new List<SelectListItem>();

 // List of carrier org code from Store procedure
 var orgCodes = containerObj.GET_CW1_SCAC_ORGCODE(scac);

// Translate it to the selectlist item
                    foreach (var item in orgCodes)
                    {
                        corgCodeLst.Add(new SelectListItem
                        {
                            Text = item.SCAC,
                            Value = item.OrgCode
                        });
                    }
   
   // return as Json , focus only on the orgcode , others is differnet purpose here
    return Json(new { orgcode = corgCodeLst, ckey = cKey, cr = carrier, sc = scac, or = cOrgCode, r = result }, JsonRequestBehavior.AllowGet);     

// view
$.ajax({
                url: '@Url.Action("yourmethid", "mvccontroller")' ,
                data: JSON.stringify(parm),
                type: "POST",
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                success: function (res) {
                  
                        $('#IC_ContainerKey').val(res.ckey);
                        $('#txtCarrier').val(res.cr);
                        $('#txtSCAC').val(res.sc);
                       
                        $('#ddlOrg').find('option').remove();
                        $(res.orgcode).each(function (index, item) {
                            $("#ddlOrg").append($('<option></option>').val(item.Text).html(item.Value));
                        });
                        $("#ddlOrg").chosen("destroy").chosen();
                      },
              
            });


// html
<select class="dropdown" id="ddlOrg"></select>
Comment

PREVIOUS NEXT
Code Example
Javascript :: useLinkClickHandler 
Javascript :: javascript checkbox in table cell not working 
Javascript :: node.js sign in to website and get contents of new page 
Javascript :: javascript loop through array of objects es6 
Javascript :: javascript sizeof array 
Javascript :: Arrow Function Shorthand javascript 
Javascript :: double bitwise not shorthand javascript 
Javascript :: ingore render on refresh page 
Javascript :: close element on click outside 
Javascript :: server starter code in js 
Javascript :: ASPxGridView - How to trigger the CustomButtonCallback event 
Javascript :: trigger many calls JavaScript 
Javascript :: how to send email 
Javascript :: jasmine configrations 
Javascript :: firebase recaptcha using react js 
Javascript :: load mulitple elements in route v6 
Javascript :: pass values and functions from a Child component to a Parent using a ref 
Javascript :: unable to append div multiple times 
Javascript :: code mirror detect change 
Javascript :: nyaapi node 
Javascript :: javascript keyup original src element 
Javascript :: how can click div close and open next day jquery 
Javascript :: angular crud rest api medium 
Javascript :: get data form and map in react js 
Javascript :: const and let keywords in ES6 
Javascript :: Async functions and execution order 
Javascript :: expo google sign inredirect uri mismatch 
Javascript :: regex generator 
Javascript :: dollar sign brackets javascript 
Javascript :: how i change background of row in javascript jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =