Sitefinity在设计器

时间:2016-08-04 00:32:13

标签: sitefinity sitefinity-feather

我在设计器中使用sf-list-selector,如下所示。我看到了我的产品清单,我可以选择和排序。

<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" />

但是当我在设计器中按save时,我在日志文件中遇到异常:

  

请求的网址:   https://localhost/Sitefinity/Services/Pages/ControlPropertyService.svc/batch/fc82280c-3055-6fae-9336-ff0000e88380/?pageId=230b270c-3055-6fae-9336-ff0000e88380&mediaType=0&propertyLocalization=0     内部异常---------------类型:System.Xml.XmlException,   System.Xml,Version = 4.0.0.0,Culture = neutral,   PublicKeyToken = b77a5c561934e089消息:结束元素'PropertyValue'   来自命名空间''预期。从命名空间''找到元素'item'。     来源:System.Runtime.Serialization帮助链接:LineNumber:0     LinePosition:0 SourceUri:数据:   System.Collections.ListDictionaryInternal TargetSite:Void   ThrowXmlException(System.Xml.XmlDictionaryReader,System.String,   System.String,System.String,System.String)HResult:-2146232000     堆栈跟踪:at   System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader   reader,String res,String arg1,String arg2,String arg3)        在System.Xml.XmlExceptionHelper.ThrowEndElementExpected(XmlDictionaryReader)   reader,String localName,String ns)        在System.Xml.XmlBaseReader.ReadEndElement()        在System.Xml.XmlBaseReader.ReadElementContentAsString()        在ReadWcfControlPropertyFromJson(XmlReaderDelegator,XmlObjectSerializerReadContextComplexJson,XmlDictionaryString,   XmlDictionaryString [])        在System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator)   jsonReader,XmlObjectSerializerReadContextComplexJson context)        在System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract)   dataContract,XmlReaderDelegator reader)        在System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator)   reader,String name,String ns,Type declaredType,DataContract&amp;   dataContract)        在System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator)   xmlReader,Int32 declaredTypeID,RuntimeTypeHandle declaredTypeHandle,   字符串名称,字符串ns)        在ReadArrayOfWcfControlPropertyFromJson(XmlReaderDelegator,XmlObjectSerializerReadContextComplexJson,XmlDictionaryString,   XmlDictionaryString,CollectionDataContract)        在System.Runtime.Serialization.Json.JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator)   jsonReader,XmlObjectSerializerReadContextComplexJson context)        在System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract)   dataContract,XmlReaderDelegator reader)        在System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator)   reader,String name,String ns,Type declaredType,DataContract&amp;   dataContract)        在System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator)   xmlReader,Type declaredType,DataContract dataContract,String name,   字符串ns)        在System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator)   xmlReader,Boolean verifyObjectName)        在System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator)   reader,Boolean verifyObjectName,DataContractResolver   dataContractResolver)

我没有视图的JSON或JS文件。当我使用这个变化为单项选择所有工作好。

1 个答案:

答案 0 :(得分:2)

事实证明,sf-selected-ids属性的值需要采用JSON数组格式。例如[productId1,productId2,productId3]。否则后端服务会抛出该异常。但是,选择器本身会将字符串创建为product1,product2,product3。即没有括号。 (您可以在设计师的高级视图中看到这一点。)

以下是详细步骤:

以下是设计器视图中的选择器(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反序列化器为控制器索引操作获取一系列产品:

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


       }        
   }
相关问题