当前位置: 首页>>代码示例>>C#>>正文


C# IUpdateModel.TryUpdateModelAsync方法代码示例

本文整理汇总了C#中IUpdateModel.TryUpdateModelAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IUpdateModel.TryUpdateModelAsync方法的具体用法?C# IUpdateModel.TryUpdateModelAsync怎么用?C# IUpdateModel.TryUpdateModelAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUpdateModel的用法示例。


在下文中一共展示了IUpdateModel.TryUpdateModelAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EditAsync

        public override async Task<IDisplayResult> EditAsync(ContentItem model, IUpdateModel updater)
        {
            // This method can get called when a new content item is created, at that point
            // the query string contains a ListPart.ContainerId value, or when an
            // existing content item has ContainedPart value. In both cases the hidden field
            // needs to be rendered in the edit form to maintain the relationship with the parent.

            if (model.Is<ContainedPart>())
            {
                return BuildShape(model.As<ContainedPart>().ListContentItemId);
            }

            var viewModel = new EditContainedPartViewModel();
            if ( await updater.TryUpdateModelAsync(viewModel, "ListPart"))
            {
                // We are editing a content item that needs to be added to a container
                // so we render the container id as part of the form

                return BuildShape(viewModel.ContainerId);
            }

            return null;
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:23,代码来源:ContainedPartDisplayDriver.cs

示例2: FilterAsync

        public async Task FilterAsync(IQuery<ContentItem> query, ListContentsViewModel model, PagerParameters pagerParameters, IUpdateModel updateModel)
        {
            var viewModel = new ListPartContentAdminFilterModel();
            if(await updateModel.TryUpdateModelAsync(viewModel, ""))
            {
                // Show list content items 
                if (viewModel.ShowListContentTypes)
                {
                    var listableTypes = _contentDefinitionManager
                        .ListTypeDefinitions()
                        .Where(x =>
                            x.Parts.Any(p =>
                                p.PartDefinition.Name == nameof(ListPart)))
                        .Select(x => x.Name);

                    query.With<ContentItemIndex>(x => x.ContentType.IsIn(listableTypes));
                }

                // Show contained elements for the specified list
                else if(viewModel.ListContentItemId != 0)
                {
                    query.With<ContainedPartIndex>(x => x.ListContentItemId == viewModel.ListContentItemId);
                }
            }
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:25,代码来源:ListPart.cs

示例3: PartEditorUpdate

 public override IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
 {
     var model = new ContentPartSettings();
     updateModel.TryUpdateModelAsync(model, "ContentPartSettings").Wait();
     builder.Attachable(model.Attachable);
     builder.WithDescription(model.Description);
     yield return DefinitionTemplate(model);
 }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:8,代码来源:EditorEvents.cs

示例4: UpdateAsync

        public override async Task<IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater)
        {
            var viewModel = new EditContainedPartViewModel();

            if (await updater.TryUpdateModelAsync(viewModel, "ListPart"))
            {
                model.Weld<ContainedPart>();
                model.Alter<ContainedPart>(x => x.ListContentItemId = viewModel.ContainerId);
            }

            return await base.UpdateAsync(model, updater);
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:12,代码来源:ContainedPartDisplayDriver.cs

示例5: TypeEditorUpdate

        public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var model = new ContentTypeSettingsViewModel();
            updateModel.TryUpdateModelAsync(model, "ContentTypeSettingsViewModel").Wait();

            builder.Creatable(model.Creatable);
            builder.Listable(model.Listable);
            builder.Draftable(model.Draftable);
            builder.Securable(model.Securable);
            builder.WithSetting("Stereotype", model.Stereotype);

            yield return DefinitionTemplate(model);
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:13,代码来源:EditorEvents.cs

示例6: UpdateAsync

        public override async Task<IDisplayResult> UpdateAsync(ContentItem contentItem, IUpdateModel updater)
        {
            var testContentPart = contentItem.As<TestContentPartA>();

            if (testContentPart == null)
            {
                return null;
            }

            if (await updater.TryUpdateModelAsync(testContentPart, ""))
            {
                if (testContentPart.Line.EndsWith(" "))
                {
                    updater.ModelState.AddModelError(nameof(testContentPart.Line), "Value cannot end with a space");
                }
                else
                {
                    contentItem.Weld(testContentPart);
                }
            }
            
            return Shape("TestContentPartA_Edit", testContentPart).Location("Content");
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:23,代码来源:TestContentDisplay.cs


注:本文中的IUpdateModel.TryUpdateModelAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。