本文介绍了您好,如何从downdownlist填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你好, 请我正在尝试从下拉列表中填写文本框(地址)(名称)选择姓名请帮我解决这个问题,因为我昨天遇到了问题:( 这是我写的代码 最好的问候。 我尝试了什么: Hello , Please i'm trying to fill the textbox (address) from dropdownlist (Name) selected Name Please Help me with this i'm stuck with problem since yesterday :( Here's the code i wrote Best Regards.What I have tried:My View ------<pre> <div class="editor-label"> @Html.LabelFor(model => model.recieverName) </div> <div class="editor-field"> @Html.DropDownListFor(model => model.recieverName, listOfDealers,"-Select-", new { id = "name1", style = "width:180px;" }) </div> <div class="editor-label"> @Html.LabelFor(model => model.senderAddress) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.recieverAddress, new { id = "addresstxt", style = "width:180px; cursor:default;" }) </div> <script type="text/javascript"> jQuery(document).ready(function () { $("#name1").change(function () { var ServiceUrl = "/Sheet/GetAddress?fname=" + fname; var content = ''; $.support.cors = true; $.ajax({ type: 'POST', url: ServiceUrl, async: true, cache: false, crossDomain: true, contentType: "application/json; charset=utf-8", dataType: 'json', error: function (xhr, err) { }, success: function (query) { $('#addresstxt').val(query.Value); } }); }); }); My conroller ----------------<pre> [HttpGet] public JsonResult GetAddress(DealerModel dlr , string fname ) { //According id to query the database and get the relevant values. using (TICK_DBEntities db = new TICK_DBEntities()) { var query = db.TICK_Dealers.Where(c => c.fullName == fname).Select(c => new {Address = c.address, MobileNo = c.mobileNo }).FirstOrDefault(); return Json(query, JsonRequestBehavior.AllowGet); } }< 推荐答案 (#name1)。change(function(){ var ServiceUrl =/ Sheet / GetAddress?fname =+ fname; var content =''; ("#name1").change(function () { var ServiceUrl = "/Sheet/GetAddress?fname=" + fname; var content = ''; .support.cors = true; .support.cors = true; .ajax({类型:'POST', url:ServiceUrl, async:true, cache:false, crossDomain :true, contentType:application / json; charset = utf-8, dataType:'json', error:function(xhr,err){}, 成功:函数(查询){.ajax({ type: 'POST', url: ServiceUrl, async: true, cache: false, crossDomain: true, contentType: "application/json; charset=utf-8", dataType: 'json', error: function (xhr, err) { }, success: function (query) { 这篇关于您好,如何从downdownlist填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 09:21