0

我有允许多个值的实体字段“标签”,如果我以这种方式为此字段创建默认值:

[{entity1-guid},{entity2-guid}] 当我使用该字段创建新对象时,一切正常。

但是如果我想对新对象使用预填充而不使用默认值,因为它依赖于其他一些逻辑,比如:

@Edit.Toolbar(actions: "new", contentType: "Doc", prefill: new { Tags = Content.Tags[0].EntityGuid } )

也可以正常工作,但是如果我想要多个预填充值,则会出现问题。

尝试这种方式时:

@Edit.Toolbar(actions: "new", contentType: "Doc", prefill: new { Tags = [{Content.Tags[0].EntityGuid},{Content.Tags[1].EntityGuid]} } )

我得到错误:

Error: System.Web.HttpCompileException (0x80004005): c:\DevFolder\DNN\dev.dnn.temp\httpdocs\Portals\0\2sxc\nn-doc\_DocList.cshtml(9): error CS1525: Invalid expression term '[' at System.Web.Compilation.AssemblyBuilder.Compile() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) at System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath virtualPath) at ToSic.SexyContent.Engines.RazorEngine.CreateWebPageInstance() in C:\Projects\2SexyContent\Web\DesktopModules\ToSIC_SexyContent\2Sexy Content Razor\RazorEngine.cs:line 81 at ToSic.SexyContent.Engines.RazorEngine.InitWebpage() in C:\Projects\2SexyContent\Web\DesktopModules\ToSIC_SexyContent\2Sexy Content Razor\RazorEngine.cs:line 110 at ToSic.SexyContent.Engines.RazorEngine.Init() in C:\Projects\2SexyContent\Web\DesktopModules\ToSIC_SexyContent\2Sexy Content Razor\RazorEngine.cs:line 27 at ToSic.SexyContent.Engines.EngineBase.Init(Template template, App app, ModuleInfo hostingModule, IDataSource dataSource, InstancePurposes instancePurposes, SxcInstance sexy) in C:\Projects\2SexyContent\Web\DesktopModules\ToSIC_SexyContent\SexyContent\Engines\EngineBase.cs:line 60 at ToSic.SexyContent.SxcInstance.GetRenderingEngine(InstancePurposes renderingPurpose) in C:\Projects\2SexyContent\Web\DesktopModules\ToSIC_SexyContent\SexyContent\SxcInstance.cs:line 244 at ToSic.SexyContent.SxcInstance.Render() in C:\Projects\2SexyContent\Web\DesktopModules\ToSIC_SexyContent\SexyContent\SxcInstance.cs:line 200

这是一个真正的错误,还是我做错了什么?

4

1 回答 1

1

我查看了您的案例,发现它已经得到支持。我认为您在标签中构建字符串数组时做错了。这是一个有效的解决方案:

@Edit.Toolbar(actions: "new", 
contentType: "BlogPost", 
prefill: new { Tags = new string[] {
    "08387a10-1aac-494a-9eb5-1383e31490eb",
    "b498a694-047a-4e51-a285-50f9a64edda1"
} })
于 2017-05-10T20:38:37.730 回答