如何在文本框中显示数据表的地址。 [英] How Can I Show My Address Of Data Table In Textbox.
本文介绍了如何在文本框中显示数据表的地址。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
namespace tableshow.Controllers
{
public class TableShowController:Controller
{
private TableShowEntities db = new TableShowEntities();
public ActionResult show()
{
ViewBag.TableShowsData = db.TableShows.ToList();
return View();
}
}
}
查看:
@ model tableshow.Models.TableShow
@ {
ViewBag.Title =show;
}
< p >
@ Html.DropDownListFor(
Model => Model.Name,
new SelectList(
ViewBag.TableShowsData as System.Collections。 IEnumerable,
Id,姓名),
选择学生,
新{@id =ddlNames}
)
< / p >
型号:
命名空间 tableshow.Models
{
使用系统;
使用 System.Collections.Generic;
public partial class TableShow
{
public int Id {获得跨度>; set ; }
public string 名称{ get 跨度>; set ; }
public string 地址{ get 跨度>; set ; }
}
}
解决方案
尝试类似的东西
(' #your-select')。change( function (){
var Id = ' 获取值如果您的名字为;
.ajax({
url:' url,它为您提供地址',
数据:Id,
成功:功能(结果){
// 此处更改地址价值
}
});
公开JsonResult GetAddressById( int Id)
{
return AddressById;
}
namespace tableshow.Controllers
{
public class TableShowController : Controller
{
private TableShowEntities db = new TableShowEntities();
public ActionResult show()
{
ViewBag.TableShowsData = db.TableShows.ToList();
return View();
}
}
}
VIEW:
@model tableshow.Models.TableShow
@{
ViewBag.Title = "show";
}
<p>
@Html.DropDownListFor(
Model => Model.Name,
new SelectList(
ViewBag. TableShowsData as System.Collections.IEnumerable,
"Id","Name"),
"Select a Student",
new { @id = "ddlNames" }
)
</p>
MODEL:
namespace tableshow.Models
{
using System;
using System.Collections.Generic;
public partial class TableShow
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
}
解决方案
Try something Like that
('#your-select').change(function() { var Id= 'Get value if For your name';
.ajax({ url:'url which gives you address', data:Id, success: function (result) { // here change value of address } });
Public JsonResult GetAddressById(int Id) { return AddressById; }
这篇关于如何在文本框中显示数据表的地址。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文