通过Web服务调用SaveChanges

时间:2016-09-04 15:52:42

标签: javascript c# asp.net ajax entity-framework

我尝试使用EF6通过Web服务在Db中保存数据,但它会永远运行而不会出现任何错误指示。

我的网络方法:

[System.Web.Script.Services.ScriptService]
    public class FamilyRelationService : System.Web.Services.WebService
    {

        [WebMethod]
        public int Update(int id, string name)
        {
            int result = -1;
            try
            {
                using (HRCTX ctx = new HRCTX())
                {
                    using (FamilyRelationRepository familyRelationRepo = new FamilyRelationRepository(ctx))
                    {
                        FAMILYRELATION family = familyRelationRepo.Find(id);

                        family.RELATION_NAME = name;
                        family.State = StateInterface.State.Modified;
                        familyRelationRepo.InsertOrUpdate(family);
                        result = ctx.Save();
                    }
                }
            }
            catch (Exception ee)
            {

                throw;
            }
            return result;
        }
    }

我的通话功能:

function Update(e) {

            name = $("#txt_relation_name").val();
             id = $("#lbl_relation_code").text();
            $.ajax({
                type: "POST",
                url: "FamilyRelationService.asmx/Update",
                data: "{'id':'" + id + "', 'name':'" + name + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var result = response.d;
                    if (result > 0) {
                        $("#name", row).text(name);
                        row.removeClass("highlightRow");
                        CloseEditStudentDialog();
                    }
                    else {
                        alert('Error...');
                    }
                },
                failure: function (msg) {
                    alert(msg);
                }
            });
            return false;
        }
 <input type="submit" id="btn_save" value="Save" onclick="Update(); return false;" />

在FireBug控制台中:

我看到以下内容: enter image description here

0 个答案:

没有答案