Sitefinity 羽化设计器中的多个内容项选择器异常

Sitefinity feather multiple content items selectors exception in designer

我正在使用 sf-list-selector 在我的设计器中,如下所示。我看到我的产品列表,我可以 select 和排序。

<sf-list-selector sf-dynamic-items-selector sf-provider="properties.ProductProviderName.PropertyValue" sf-item-type="properties.ProductType.PropertyValue" sf-multiselect="true" sf-sortable="true" sf-master="true" sf-selected-ids="properties.ProductIds.PropertyValue" />

但是,当我在设计器中按保存时,日志文件中出现异常:

Requested URL : https://localhost/Sitefinity/Services/Pages/ControlPropertyService.svc/batch/fc82280c-3055-6fae-9336-ff0000e88380/?pageId=230b270c-3055-6fae-9336-ff0000e88380&mediaType=0&propertyLocalization=0 Inner Exception --------------- Type : System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : End element 'PropertyValue' from namespace '' expected. Found element 'item' from namespace ''. Source : System.Runtime.Serialization Help link : LineNumber : 0 LinePosition : 0 SourceUri : Data : System.Collections.ListDictionaryInternal TargetSite : Void ThrowXmlException(System.Xml.XmlDictionaryReader, System.String, System.String, System.String, System.String) HResult : -2146232000 Stack Trace : at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3) at System.Xml.XmlExceptionHelper.ThrowEndElementExpected(XmlDictionaryReader reader, String localName, String ns) at System.Xml.XmlBaseReader.ReadEndElement() at System.Xml.XmlBaseReader.ReadElementContentAsString() at ReadWcfControlPropertyFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString[] ) at System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns) at ReadArrayOfWcfControlPropertyFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString , CollectionDataContract ) at System.Runtime.Serialization.Json.JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns) at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)

我没有 JSON 或视图的 JS 文件。当我将此变体用于单个项目时 select 一切正常。

事实证明,sf-selected-ids 属性的值需要采用 JSON 数组格式。例如[ 产品 ID1、产品 ID2、产品 ID3]。否则后端服务会抛出该异常。但是,选择器自己将字符串创建为 product1、product2、product3。 IE。没有括号。 (在设计器的高级视图中可以看到)

所以这里是详细步骤:

这是设计器视图中的选择器 (DesignerView.Simple.cshtml):

<sf-list-selector sf-dynamic-items-selector sf-provider="properties.ProductProviderName.PropertyValue" sf-item-type="properties.ProductType.PropertyValue" sf-multiselect="true" sf-sortable="true" sf-master="true" sf-selected-ids="productIds" />

您需要设计器 JS 文件来回执行 JSON 转换。所以我把它保存在 MVC/Scripts/[WidgetName]/designer-simple.json 中:(简单是设计器视图的名称)

(function ($) {

    var designerModule = angular.module('designer');
    angular.module('designer').requires.push('sfSelectors');

    designerModule.controller('SimpleCtrl', ['$scope', 'propertyService', function ($scope, propertyService) {

        $scope.feedback.showLoadingIndicator = true;
        propertyService.get().then(function (data) {
            if (data) {
                $scope.properties = propertyService.toAssociativeArray(data.Items);
            }
        },
        function (data) {
            $scope.feedback.showError = true;
            if (data)
                $scope.feedback.errorMessage = data.Detail;
        }).finally(function () {
            $scope.feedback.showLoadingIndicator = false;
        });

        $scope.$watch('properties.ProductIds.PropertyValue', function (newValue, oldValue) {
            if (newValue) {               
                $scope.productIds = JSON.parse(newValue);
            }
        });

        $scope.$watch('productIds', function (newValue, oldValue) {
            if (newValue) {               
                $scope.properties.ProductIds.PropertyValue = JSON.stringify(newValue);
            }
        });

    }]);

})(jQuery);

最后我在 DesignerView.Simple.cshtml 所在的文件夹中添加了一个 DesignerView.Simple.json 文件:

{
    "priority": 1,
    "scripts": [     
        "client-components/selectors/common/sf-selected-items-view.js"
    ],
    "components" : ["sf-dynamic-items-selector"]
}

小部件控制器有一个 ProductIds 属性。其值的格式为 [productId1、productId2 等]。我使用 JSON 解串器为控制器 Index 操作获取一组产品:

public class ProductListController : Controller
   {
       private string productProviderName = WebConfigurationManager.AppSettings["productProviderName"];
       private string productTypeName = WebConfigurationManager.AppSettings["productTypeName"];

       public string ProductIds { get; set; }

       public string ProductType
       {
           get { return productTypeName; }
           set { productTypeName = value; }
       }

       public string ProductProviderName
       {
           get { return productProviderName; }
           set { productProviderName = value; }
       }

       public ActionResult Index()
       {
           var selectedProducts = string.IsNullOrEmpty(this.ProductIds) ? new Guid[0] : JsonConvert.DeserializeObject<Guid[]>(this.ProductIds);

         // ... rest of your controller index action


       }        
   }