我正在努力使用ASP.NET MVC处理Kentico表单的API调用,以便可以使用AngularJS显示返回数据(JSON格式)。
具体来说,我的客户在其服务器上使用Kentico在Kentico上使用“表单”创建数据,我想使用ASP.NET MVC通过API调用获取存储在这些表单中的记录。我在想的是,在“表单”的常规部分中,我看到“表单代码名称”显示“代码名称是对象的字符串标识符,开发人员可以在API调用或URL中使用它”。但这似乎在互联网上没有很好的例子。继续尝试搜索它,但是没有运气。我还尝试直接在kentico存储数据的SQL Server中访问数据。但是,Kentico在SQL Server中用于存储数据的表名与Kentico的“表单”或“自定义表”中的表名不同。
希望有人能告诉我该怎么做,我真的很感激。提前致谢。
在Kentico的官方文档中有一个很好的例子。请注意,表单过去曾被重命名几次(它们分别称为BizForms和On-Line表单),这就是下面的代码引用CMS.OnlineForms
和使用的原因BizFormInfoProvider
。这也很可能是您找不到任何好例子的原因:)
下面的示例显示了如何检索Form的定义(元数据),获取所有数据并对其进行迭代。
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);
}
}
更新:上面的示例假设您正在运行的Kentico实例中使用API。如果要从外部应用程序使用Kentico API(DLL),请按照我在另一个答案中描述的步骤进行操作。
您还询问了站点标识符(方法的siteId或siteName参数BizFormInfoProvider.GetBizFormInfo()
)。它们引用SiteInfo
Kentico中的对象(数据库表CMS_Site
)。如果导航到,则可以找到站点名称Site->Edit site->General->Site code name
。
如果您不想使用Kentico DLL,则还有另一种选择-使用Kentico REST端点。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句