大家好,我是使用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
发布评论