自动重新加载div内容时,按钮单击不在div内容中工作

时间:2017-11-27 07:22:29

标签: jquery asp.net-mvc-5

我有一个部分页面,我试图在时间间隔内重新加载,如2/5秒。模型绑定中的部分页面加载。局部 页面名称如" _OutletTable.cshtml"它在索引页面中加载。 在针对每个li添加项目时,li会在重新加载操作中更新。 但是当点击li然后它没有工作。

     @using PepperoniApp.Models
    @model MultiplePoSmodel
    <ul class="tablenameorderstatus">
        @foreach (var item in Model.Tables)
        {
            var orderstatus = item.OrderStatus.ToLower();
            var colstatus = item.Collection.ToLower();
            var colorName = string.Empty;

            switch (orderstatus ?? string.Empty)
            {
                case " ":
                    colorName = "green";
                    break;
                case "n":
                case "r":
                    colorName = "dark-yellow";
                    break;
                case "d":
                    colorName = colstatus == "b" ? "brown" : "orange";
                    break;

            }

            <li data-tableid="@item.TableId" data-kotorderid="@item.KotOrderId" data-outletid="@item.Oid">
                <a href="#" class="btn  @colorName tableName table-order-detail"><i class="icon-food"></i><span>@item.TableName</span></a>
            </li>

        }
    </ul>



this is the index page I have to render action to load the partial page.    
    <div id="tablecontainer" class="metro-sidenav-table scrollbar-rail">
                        <h4 class="side-head">Table</h4>
                        <div id="divtableload">
                            @{Html.RenderAction("FetchTable");}

                        </div>

                    </div>


partial page controller with action code given below: 


    public ActionResult FetchTable()
            {
                try
                {
                    Int32 storeid = Convert.ToInt32(Session["StoreId"]);
                    MultiplePoSmodel multiple = new MultiplePoSmodel();
                    List<TableModel> tablelist =
                        dbEntities.GET_ALL_OUTLET_TABLE_NAME(storeid).AsEnumerable().Select(s => new TableModel()
                        {
                            TableId = s.TABLE_ID,
                            TableName = s.TABLE_NAME.ToString(),
                            TableType = s.TABLE_TYPE,
                            Oid = s.OID,
                            OrderStatus = s.ORDER_STATUS,
                            KotOrderId = s.ORDERID,
                            TableStatus = s.TABLE_STATUS,
                            Collection = s.COL_STATUS
                        }).ToList();
                    multiple.Tables = tablelist;
                    return PartialView("_OutletTable", multiple);
                }
                catch (Exception e)
                {
                    return Json(e.Message, JsonRequestBehavior.AllowGet);
                }
            }

 every 15000 millisecond page reload for partial page with this jquery which is given below:

    setInterval(function () {
                var url = '@Url.Action("FetchTable")';
                var notifications = $("#divtableload");
                notifications.load(url);
            }, 15000);
but problem is when i click li thats not working like:

    $('.tableName')
                .click(function() {
                    debugger;
                    var outletid = $(this).closest('li').data('outletid');
                    var tableid = $(this).closest('li').data('tableid');
                    var tablename = $(this).closest('li').text();
                    var kotorderid = $(this).closest('li').data('kotorderid');
    });

0 个答案:

没有答案