【问题标题】:SharePoint 2013 App - CRUD operationSharePoint 2013 应用程序 - CRUD 操作
【发布时间】:2014-05-09 05:04:08
【问题描述】:

我是带有外部内容的 Sharepoint 2013 应用程序的新手。我可以从 SQL 中提取数据并填充到 App 页面中。但是我尝试添加新数据,我收到以下错误消息


来自网页的消息

{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.\"}}}","status":400,"statusText":"Bad Request"}

好的

我使用了以下代码

create: function (dname, description) {
    debugger;
    $.ajax({
        url: _spPageContextInfo.webServerRelativeUrl +
                    "/_api/web/lists/getByTitle('tblDomain_SP')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify({'DomainName':dname,'Description':description}),
        dataType: "json",
        headers: {
            "accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function () {
            REST.DomainFormFiller.clear();
        },
        error: function (err) {
            alert(JSON.stringify(err));
        }

    });

}

您能帮我将数据插入到 sql 表吗?

【问题讨论】:

    标签: c# sql sharepoint


    【解决方案1】:

    错误:

    找到没有类型名称的条目,但没有预期的类型 指定的。为了允许没有类型信息的条目,预期的 指定模型时也要指定类型

    由于列表项条目中缺少Type 属性而发生。

    列出项目类型

    要创建列表项,您需要包含列表项类型。这是首次创建列表时由 SharePoint 自动创建的字符串。两种可能的方法是:

    • 对列表执行读取操作并在列表中找到类型 返回的元素集。在 JSON 格式中,可以在其中找到类型 所有返回列表项的__metadata 属性。
    • 您可以尝试从列表名称中生成值。一般来说 列表项类型遵循约定SP.Data.ListNameListItem(例如 列表名称为Test,列表项类型为SP.Data.TestListItem)。然而 这并非总是如此。例如 SharePoint 自动 将列表名称的第一个字母大写(例如,列表名称test 列表项类型为SP.Data.TestListItem)。

    解决方案

    下面的代码sn-p展示了如何根据列表名称生成List Item Type:

    function GetItemTypeForListName(name) {
        return"SP.Data." + name.charAt(0).toUpperCase() + name.slice(1) + "ListItem";
    }
    

    那你需要换行:

    data: JSON.stringify({'DomainName':dname,'Description':description}),
    

    用这个:

    data: JSON.stringify({'DomainName':dname,'Description':description,"__metadata": { "type": GetItemTypeForListName('tblDomain_SP') }}), 
    

    参考文献

    Manipulating list items in SharePoint Hosted Apps using the REST API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      相关资源
      最近更新 更多