【问题标题】:Web API Client Posting Not Hitting DatabaseWeb API 客户端发布未命中数据库
【发布时间】:2013-05-22 07:17:35
【问题描述】:

请帮助 ASP.NET MVC 4 Web Api 项目。我可以毫不费力地从我的 api 控制器中检索 JSON,并且发布似乎有效(我的 UI 已更新),但数据没有进入数据库。

// POST api/待办事项 公共 HttpResponseMessage 帖子(待办事项) { item = _db.Todoes.Add(item); var response = Request.CreateResponse(HttpStatusCode.Created, item);

        string uri = Url.Link("DefaultApi", new { id = item.TodoId });
        response.Headers.Location = new Uri(uri);
        return response;
    }

      self.create = function (formElement) {
          // If valid, post the serialized form data to the web api
          //$(formElement).validate();
          //if ($(formElement).valid()) {
              $.post(baseUri, $(formElement).serialize(), null, "json")
                  .done(function (o) { self.todoes.push(o); });
          //}
      }

'我做错了吗?

【问题讨论】:

    标签: asp.net-mvc-4 asp.net-web-api


    【解决方案1】:

    谢谢大家。我现在有了答案... _db.SaveChanges() 提交到数据库。

    【讨论】:

      猜你喜欢
      • 2012-06-24
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      相关资源
      最近更新 更多