我有实体字段“Tags”允许多个值,如果我为这个字段创建默认值:
[{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
这是一个真正的错误,还是我做错了什么?
答案 0 :(得分:1)
我查看了您的案例,发现它已经受到支持。我认为你在标签中构建字符串数组时遇到了一些问题。这是一个有效的解决方案:
@Edit.Toolbar(actions: "new",
contentType: "BlogPost",
prefill: new { Tags = new string[] {
"08387a10-1aac-494a-9eb5-1383e31490eb",
"b498a694-047a-4e51-a285-50f9a64edda1"
} })