如何使用存储库获取选定的ID

编程入门 行业动态 更新时间:2024-10-21 19:44:40
本文介绍了如何使用存储库获取选定的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,我是使用Razor MVC的新手。 我有一个dropdownlist的部分视图。我已经获得了下拉列表的显示列表,但所选ID是0它应该有价值。下面是我的酸性代码: 主要观点:

Hi all, I am new using Razor MVC. I have one partial view for dropdownlist.I already get display list for dropdownlist but for selected ID is 0. It should be have value.Below is my sourcode: Main View:

<p>CUSTOMER INFORMATION</p> <table> <tr> <td><label for="customer">Customer</label></td> <td><div id="CustomerContainer">@Html.Action("CustomerView")</div></td> </tr> <tr> <td><label for="inCharge">Contact Person</label></td> <td><div id="InCharge">@Html.Action("CustomerDetailsView")</div></td> </tr>

部分视图(CustomerView): 在此下拉列表中选择客户

Partial View(CustomerView): Choose Customer in this dropdownlist

@Html.DropDownListFor(p=>p.SelectedCustomerID , Model.CustomerIEnum, "Select Customer", new{@id="Customer-DropdownID", @class="Customer-DropdownCls"})

<script type="text/javascript"> $(function () { // Populate State/Provinces $('#Customer-DropdownID').change(function () { var selectedCustomerID = this.value; $('#InCharge').load('@Url.Action("CustomerDetailsView")?customerID=' + selectedCustomerID); }); }); </script>

部分视图(客户详情查看) 将显示负责人。

Partial View(Customer Details View) will Display Person In Charge.

@Html.DisplayFor(model => model.PIC)

控制器: 公共静态BusinessLogic.ViewModel.CustomerViewModel customervm = new BusinessLogic.ViewModel .CustomerViewModel();

Controller: public static BusinessLogic.ViewModel.CustomerViewModel customervm = new BusinessLogic.ViewModel.CustomerViewModel();

public ActionResult CustomerDetailsView(int? customerID) {using (BulkMailing2015Context db = new BulkMailing2015Context(connection)) { if (customerID != null) {var q = db.Customers.Select(p => p.CustomerID == customerID); customervm.SelectedCustomerID.CompareTo(q); } } return View(customervm); }

CustomerViewModel:

CustomerViewModel:

public Int32 SelectedCustomerID { get; set; } public string PIC { get { var q = from tbl in CustomerList where tbl.CustomerID == SelectedCustomerID select tbl.InCharge; return q.ToString(); } }

谢谢提前

Thanks in advance

推荐答案

(function(){ //填充州/省份 (function () { // Populate State/Provinces

('#Customer- DropdownID')。change(function(){ var selectedCustomerID = this.value; ('#Customer-DropdownID').change(function () { var selectedCustomerID = this.value;

('#InCharge')。load('@ Url.Action(CustomerDetailsView) )?customerID ='+ selectedCustomerID); }); }); < / script> ('#InCharge').load('@Url.Action("CustomerDetailsView")?customerID=' + selectedCustomerID); }); }); </script>

部分视图(客户详情查看) 将显示负责人。

Partial View(Customer Details View) will Display Person In Charge.

@Html.DisplayFor(model => model.PIC)

控制器: 公共静态BusinessLogic.ViewModel.CustomerViewModel customervm = new BusinessLogic.ViewModel .CustomerViewModel();

Controller: public static BusinessLogic.ViewModel.CustomerViewModel customervm = new BusinessLogic.ViewModel.CustomerViewModel();

public ActionResult CustomerDetailsView(int? customerID) {using (BulkMailing2015Context db = new BulkMailing2015Context(connection)) { if (customerID != null) {var q = db.Customers.Select(p => p.CustomerID == customerID); customervm.SelectedCustomerID.CompareTo(q); } } return View(customervm); }

CustomerViewModel:

CustomerViewModel:

public Int32 SelectedCustomerID { get; set; } public string PIC { get { var q = from tbl in CustomerList where tbl.CustomerID == SelectedCustomerID select tbl.InCharge; return q.ToString(); } }

谢谢提前

Thanks in advance

更多推荐

如何使用存储库获取选定的ID

本文发布于:2023-11-28 16:33:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!