Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在MVCMobile中单击按钮即可显示列表中的不同项目_Jquery_Asp.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Jquery 在MVCMobile中单击按钮即可显示列表中的不同项目

Jquery 在MVCMobile中单击按钮即可显示列表中的不同项目,jquery,asp.net,asp.net-mvc,asp.net-mvc-4,Jquery,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我的客户列表中有一个客户列表 List<Customer> customers= GetCustomer("New York"); List customers=GetCustomer(“纽约”); 我想在MVC视图中单击左右按钮显示每个客户项目,最后保存客户 我的MVC视图如下所示 |左按钮|第1个,共5个|右按钮| 顾客:迈克尔地址:公园大道123号, 纽约评级:4电话:123456 |按钮保存| |按钮删除| 我希望我正确地解释了这一点,我应该如何在MVC中通过部分页面更新

我的客户列表中有一个客户列表

List<Customer> customers= GetCustomer("New York");
List customers=GetCustomer(“纽约”);
我想在MVC视图中单击左右按钮显示每个客户项目,最后保存客户

我的MVC视图如下所示

|左按钮|第1个,共5个|右按钮|

顾客:迈克尔地址:公园大道123号, 纽约

评级:4

电话:123456

|按钮保存| |按钮删除|


我希望我正确地解释了这一点,我应该如何在MVC中通过部分页面更新来完成这项工作。

以下是一种可能的解决方案:

创建局部视图以显示单个客户记录

型号:

    public static Customer GetCustomerInfo(int customerId)
    {
        using (var db = new DbContext())
        {
            return db.Customers
                .Where(c => c.CustomerId == customerId)
                .FirstOrDefault();
        }
    }
视图:

在“下一步”和“上一步”按钮上,进行ajax调用以加载相应记录的部分视图html

    function loadCustomer(customerId) {
        $.ajax({
            url: '/Store/GetCustomer?customerId=' + customerId,
            type: "GET",
            dataType: "html",
            success: function (data) {
                //Fill in the div where you load the partial view with the result
                $('#customerDiv').html(data);
            }
        });
    }
在Save和Delete按钮上,进行另一个ajax调用以执行所需的操作

如果数据库中存在大量记录,则此解决方案是合适的。如果没有,您可以缓存客户端的所有数据,并仅在保存和删除时调用服务器。另一种解决方案是缓存10条记录,例如,当到达第10条记录时,缓存另一批记录

    [HttpGet]
    [Authorize]
    public ActionResult GetCustomer(int customerId)
    {
        var customer = CustomerModel.GetCustomerInfo(customerId);
        return PartialView(customer);
    }    
    function loadCustomer(customerId) {
        $.ajax({
            url: '/Store/GetCustomer?customerId=' + customerId,
            type: "GET",
            dataType: "html",
            success: function (data) {
                //Fill in the div where you load the partial view with the result
                $('#customerDiv').html(data);
            }
        });
    }