如何使用存储库获取选定的ID [英] How to Get Selected ID using repository

查看:66
本文介绍了如何使用存储库获取选定的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆