C# 如何使用ASP.NET MVC进行Kentico的API调用?

C# 如何使用ASP.NET MVC进行Kentico的API调用?,c#,asp.net,api,kentico,C#,Asp.net,Api,Kentico,我正在使用ASP.NETMVC处理Kentico表单的API调用,以便使用AngularJS显示返回数据(JSON格式) 具体地说,我的客户机正在使用服务器上的Kentico来使用Kentico上的“表单”创建数据,我希望通过使用ASP.NET MVC的API调用来获取存储在这些表单中的记录。我的想法是,在“表单”的常规部分中,我看到“表单代码名”显示“代码名是对象的字符串标识符,可供开发人员在API调用或URL中使用”。但在互联网上似乎没有这方面的好例子。继续搜索它,但没有运气。我还尝试直接访

我正在使用ASP.NETMVC处理Kentico表单的API调用,以便使用AngularJS显示返回数据(JSON格式)

具体地说,我的客户机正在使用服务器上的Kentico来使用Kentico上的“表单”创建数据,我希望通过使用ASP.NET MVC的API调用来获取存储在这些表单中的记录。我的想法是,在“表单”的常规部分中,我看到“表单代码名”显示“代码名是对象的字符串标识符,可供开发人员在API调用或URL中使用”。但在互联网上似乎没有这方面的好例子。继续搜索它,但没有运气。我还尝试直接访问SQL Server中的数据,kentico在其中存储数据。但Kentico在SQL Server中用于存储数据的表名与Kentico中“表单”或“自定义表”中的表名不同


希望有人能告诉我怎么做,我真的很感激。提前谢谢。

官方网站上有一个很好的例子。 请注意,表单在过去被重命名过几次(它们被称为BizForms和在线表单),这就是为什么下面的代码引用了
CMS.OnlineForms
,并使用
BizFormInfoProvider
。这也很可能是你没有找到好例子的原因:)

下面的示例显示了如何检索表单的定义(元数据),获取所有数据并对其进行迭代

using CMS.OnlineForms;
using CMS.DataEngine;
using CMS.SiteProvider;
using CMS.Helpers;

...

// Gets the form info object for the 'ContactUs' form
BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("ContactUs", SiteContext.CurrentSiteID);

// Gets the class name of the 'ContactUs' form
DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
string className = formClass.ClassName;

// Loads the form's data
ObjectQuery<BizFormItem> data = BizFormItemProvider.GetItems(className);

// Checks whether the form contains any records
if (!DataHelper.DataSourceIsEmpty(data))
{
    // Loops through the form's data records
    foreach (BizFormItem item in data)
    {
        string firstNameFieldValue = item.GetStringValue("FirstName", "");
        string lastNameFieldValue = item.GetStringValue("LastName", "");

        // Perform any required logic with the form field values

        // Variable representing a custom value that you want to save into the form data
        object customFieldValue;

        // Programatically assigns and saves a value for the form record's 'CustomField' field
        item.SetValue("CustomField", customFieldValue);
        item.SubmitChanges(false);
    }
}
使用CMS.OnlineForms;
使用CMS.DataEngine;
使用CMS.SiteProvider;
使用CMS.Helpers;
...
//获取“ContactUs”表单的表单信息对象
BizFormInfo formObject=BizFormInfo提供程序.GetBizFormInfo(“ContactUs”,SiteContext.CurrentSiteID);
//获取“ContactUs”窗体的类名
DataClassInfo formClass=DataClassInfo提供者.GetDataClassInfo(formObject.FormClassID);
字符串className=formClass.className;
//加载窗体的数据
ObjectQuery数据=BizFormItemProvider.GetItems(类名);
//检查表单是否包含任何记录
如果(!DataHelper.datasourceismpty(数据))
{
//循环浏览表单的数据记录
foreach(数据中的BizFormItem项)
{
string firstNameFieldValue=item.GetStringValue(“FirstName”,即“”);
string lastNameFieldValue=item.GetStringValue(“LastName”,即“”);
//使用表单字段值执行任何必需的逻辑
//表示要保存到表单数据中的自定义值的变量
对象值;
//以编程方式为表单记录的“CustomField”字段分配并保存一个值
item.SetValue(“CustomField”,customFieldValue);
项目。提交变更(假);
}
}
更新: 上面的示例假设您正在运行Kentico实例中使用API。如果您想从外部应用程序使用Kentico API(DLL),请遵循我在另一个应用程序中描述的步骤

您还询问了站点标识符(bizforminfo.GetBizFormInfo()方法的siteId或siteName参数)。它们指的是Kentico中的
SiteInfo
对象(DB table
CMS\u Site
)。如果导航到
site->Edit site->General->site code name
,则可以找到站点名称


如果您不想使用Kentico DLL,还有另一种选择-使用。

官方网站中有一个很好的例子。 请注意,表单在过去被重命名过几次(它们被称为BizForms和在线表单),这就是为什么下面的代码引用了
CMS.OnlineForms
,并使用
BizFormInfoProvider
。这也很可能是你没有找到好例子的原因:)

下面的示例显示了如何检索表单的定义(元数据),获取所有数据并对其进行迭代

using CMS.OnlineForms;
using CMS.DataEngine;
using CMS.SiteProvider;
using CMS.Helpers;

...

// Gets the form info object for the 'ContactUs' form
BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("ContactUs", SiteContext.CurrentSiteID);

// Gets the class name of the 'ContactUs' form
DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
string className = formClass.ClassName;

// Loads the form's data
ObjectQuery<BizFormItem> data = BizFormItemProvider.GetItems(className);

// Checks whether the form contains any records
if (!DataHelper.DataSourceIsEmpty(data))
{
    // Loops through the form's data records
    foreach (BizFormItem item in data)
    {
        string firstNameFieldValue = item.GetStringValue("FirstName", "");
        string lastNameFieldValue = item.GetStringValue("LastName", "");

        // Perform any required logic with the form field values

        // Variable representing a custom value that you want to save into the form data
        object customFieldValue;

        // Programatically assigns and saves a value for the form record's 'CustomField' field
        item.SetValue("CustomField", customFieldValue);
        item.SubmitChanges(false);
    }
}
使用CMS.OnlineForms;
使用CMS.DataEngine;
使用CMS.SiteProvider;
使用CMS.Helpers;
...
//获取“ContactUs”表单的表单信息对象
BizFormInfo formObject=BizFormInfo提供程序.GetBizFormInfo(“ContactUs”,SiteContext.CurrentSiteID);
//获取“ContactUs”窗体的类名
DataClassInfo formClass=DataClassInfo提供者.GetDataClassInfo(formObject.FormClassID);
字符串className=formClass.className;
//加载窗体的数据
ObjectQuery数据=BizFormItemProvider.GetItems(类名);
//检查表单是否包含任何记录
如果(!DataHelper.datasourceismpty(数据))
{
//循环浏览表单的数据记录
foreach(数据中的BizFormItem项)
{
string firstNameFieldValue=item.GetStringValue(“FirstName”,即“”);
string lastNameFieldValue=item.GetStringValue(“LastName”,即“”);
//使用表单字段值执行任何必需的逻辑
//表示要保存到表单数据中的自定义值的变量
对象值;
//以编程方式为表单记录的“CustomField”字段分配并保存一个值
item.SetValue(“CustomField”,customFieldValue);
项目。提交变更(假);
}
}
更新: 上面的示例假设您正在运行Kentico实例中使用API。如果您想从外部应用程序使用Kentico API(DLL),请遵循我在另一个应用程序中描述的步骤

您还询问了站点标识符(bizforminfo.GetBizFormInfo()方法的siteId或siteName参数)。它们指的是Kentico中的
SiteInfo
对象(DB table
CMS\u Site
)。如果导航到
site->Edit site->General->site code name
,则可以找到站点名称


如果您不想使用Kentico DLL,还有另一种选择-使用。

官方网站中有一个很好的例子。 请注意,表单在过去曾多次被重命名(称为BizForms和在线表单),这就是为什么下面的代码引用了
CMS.OnlineForms
并使用
BizFormIn的原因