Front interface, a drop-down box, a text box <select id= "SEX" > <option> men </option> <option> Women </option> <optio n> unknown </option></select><input id = "DESC" type= "text"/>
Page introduced Js<script type= "Text/javascript" src= ". /.. /scripts/myajax.js ">
All contents of Myajax.js $ (function () { $ ("#SEX"). Change (function () { $.ajax ({ type: "Post", url: "/knoledge/find", //page name (without controller)/background method name to invoke data: "{' Sex ': '" + $ (' #SEX '). Val () + "'}", / /json format strings in the background, parameter names must be consistent contentType: "Application/json; Charset=utf-8 ", datatype: " JSON ", success: function (Result) { $ ("#DESC"). attr ("value", result.id); //will get the value assigned to the foreground control, where D, If the background returned is not a JSON string, but merely a value, the returned value is included in the attribute named D }, error: function (ERR) { alert ("haha"); (&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;});});
Knoledgecontroller Find method public ActionResult find (String sex) {var tempobj = new { id = "Gender" +sex}; Return Json (Tempobj, jsonrequestbehavior.allowget); }
Just shoot like this.
ASP. NET MVC 4 Jquery Ajax