简体   繁体   English

在选定列表ID的视图中显示类别

[英]Display class in view from selected list ID

I have a listbox of licenseplates, and when I select one of the items in the list, I want to retrive the rest of the information about the licenseplate and display it in my view. 我有一个牌照列表框,当我选择列表中的一个项目时,我想检索有关牌照的其余信息并在我的视图中显示它。

I have filled my listbox with only the licenseplatenumber from a list that fills upp with the whole datatable. 我已经用仅用整个数据表填充upp的列表中的牌照号填充了列表框。 When I select the licenseplatenumber I want to display all the information from the list that I have made. 当选择车牌号时,我要显示我已完成的清单中的所有信息。

I have tried to use @Html.displayfor and then when I select an item I want to display the brand of that car. 我尝试使用@Html.displayfor ,然后选择一个项目时要显示该车的品牌。 I don't really understand how to retrive it and to display it 我不太了解如何检索和显示它

This is my Model: 这是我的模型:

 public class AdminCar 
    {
        public int CarID { get; set; }
        public string LicensePlateNumber { get; set; }
        public string Color { get; set; }
        public string Brand { get; set; }
        public string Model { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public long BirthOfDate { get; set; }
        public int VehicleFines { get; set; }
        public bool IsStolen { get; set; }
    }

This is my controller: 这是我的控制器:

        public ActionResult CarInfo()
        {
            var CarService = new CarService();
            List<Core.Entities.Response.CoreCar> cars = CarService.ListOfCars();

            List<AdminCar> aCar = new List<AdminCar>();

            foreach (var item in cars)
            {
                AdminCar car = new AdminCar
                {
                    LicensePlateNumber = item.LicensePlateNumber,
                    Brand = item.Brand,
                    Color = item.Color,
                    Model = item.Model,
                    Firstname = item.Firstname,
                    Lastname = item.Lastname,
                    BirthOfDate = item.BirthOfDate,
                    VehicleFines = item.VehicleFines,
                    IsStolen = item.IsStolen,
                };
                aCar.Add(car);

            }
            return View(aCar);
        }

This is in my View: 这是我的观点:


<select name="listbox" id="CarSelected">
    @foreach (var item in Model)
    {
        <option value="@item.LicensePlateNumber">
            @item.LicensePlateNumber                                
        </option>
    }
</select>

in this case you use ajax call to get information from server 在这种情况下,您使用ajax调用从服务器获取信息

$('#CarSelected').change(function(){ $.ajax({ url:'controller/action', type:'Get', data:{LicensePlateNumber:$('#CarSelected').val()}, success:function(infoCar){ // there update info of car by jquery } }); }); $('#CarSelected')。change(function(){$ .ajax({url:'controller / action',type:'Get',data:{LicensePlateNumber:$('#CarSelected')。val()} ,success:function(infoCar){//通过jquery}});});更新汽车的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM