下载列表在页面重新加载后未显示已保存的值

时间:2016-06-21 17:02:39

标签: javascript jquery html asp.net kendo-ui

我有一个包含2个值的页面位置的下拉列表。当我从列表中选择一个值并单击“保存”时,该值将保存在数据库中。但是当我重新加载页面时,会显示选择条件中的第一个值,当我编辑其他值并单击“保存”时,“页面位置”的值也会更改。问题是,我希望在刷新页面时看到我为页面位置更改的值。以下是我的代码。功能'编辑'当我点击编辑页面位置时调用。

HTML代码:

<script id="editTemplate" type="text/x-kendo-template">
<div class = "row">
  <div class="col-sm-8">
  <label  style="display:none;">Id:</label>
  <input type="hidden" id='ID' class="k-textbox" value="#=node.id #" />
  </div>
  <div class="col-sm-8">
  <label >PageLocation:</label>
  <select id = "pl">
  <option value="local">local</option>
  <option value="New Window" >New Window</option>
  </select>
  </div>
  <div class="col-sm-4">
  <button id="save" class="k-button k-primary">Save</button>
  </div>
  </div>

JavaScript的:

function edit(itemid){
var editTemplate = kendo.template($("#editTemplate").html());
var treeview = $("#treeview").data("kendoTreeView");
var selectedNode = treeview.select();
var node = treeview.dataItem(selectedNode);

$("<div/>")
    .html(editTemplate({ node: node}))
    .appendTo("body")
    .kendoWindow({
        modal: true,
        deactivate: function () {
            this.destroy();
        }
    })
 .on("click", ".k-primary", function (e) {     
    var dialog = $(e.currentTarget).closest("[data-role=window]").getKendoWindow();
    var textbox = dialog.element.find(".k-textbox");
    var Id = $('#ID').val();
    var PageLocation = $('#pl').val();
    node.text = undefined;
    node.set("Pagelocation", PageLocation);
    node.set("id", Id);
    dialog.close();
    var treenode = treeview.dataSource.get(itemid);
    treenode.set("Pagelocation", PageLocation);
    treenode.set("id", Id);
       treenode.PAGE_LOCATION = PageLocation;
    treenode.ID = Id;

    $.ajax({
        url: "/Services/TreeServices.asmx/UpdateTree",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        datatype: "json",
        //data: JSON.stringify({ "erpLinksJson": treenode, NodeId: nid, RoleId: rid })
        data: JSON.stringify({ "LinksJson": treenode})
    });



    console.log(JSON.stringify(treenode));
 })


}

服务:

        [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public String UpdateTree(LinksJSON LinksJson)
    {
        using (var context = new Data.WebEntities())
        {

            context.Configuration.ProxyCreationEnabled = false;
            var updNode = context.Links.Where(c => c.ID == LinksJson.ID).FirstOrDefault();
            if (updNode != null)
            {
                updNode.ID = erpLinksJson.ID;
                updNode.PAGE_LOCATION = erpLinksJson.PAGE_LOCATION;
                context.SaveChanges();
            }
            JavaScriptSerializer JSON = new JavaScriptSerializer();
            return JSON.Serialize(updNode);

        }
    }

0 个答案:

没有答案