-
-
Save sebastiandammark/e25ef34e3739ece2cfd71bc0a4218f36 to your computer and use it in GitHub Desktop.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<Website> | |
<!DOCTYPE html> | |
<head> | |
<title>Test Helpers Page</title> | |
</head> | |
<body> | |
@{ | |
var moduleList = Model.Content.Modules.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); | |
var moduleCollection = Umbraco.Content(moduleList); | |
foreach (var module in moduleCollection) | |
{ | |
@RenderContent((dynamic) module); | |
} | |
} | |
</body> | |
</html> | |
@helper RenderContent(Textelement module) | |
{ | |
<div>Textelement</div> | |
} | |
@helper RenderContent(Fullwidthmedia module) | |
{ | |
<div>Fullwidthmedia</div> | |
} |
/// <summary>Tekst element</summary>
[PublishedContentModel("textelement")]
public partial class Textelement : PublishedContentModel
{
#pragma warning disable 0109 // new is redundant
public new const string ModelTypeAlias = "textelement";
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
#pragma warning restore 0109
public Textelement(IPublishedContent content)
: base(content)
{ }
#pragma warning disable 0109 // new is redundant
public new static PublishedContentType GetModelContentType()
{
return PublishedContentType.Get(ModelItemType, ModelTypeAlias);
}
#pragma warning restore 0109
public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<Textelement, TValue>> selector)
{
return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector);
}
/// <summary>Full Width Media</summary>
[PublishedContentModel("fullwidthmedia")]
public partial class Fullwidthmedia : PublishedContentModel
{
#pragma warning disable 0109 // new is redundant
public new const string ModelTypeAlias = "fullwidthmedia";
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
#pragma warning restore 0109
public Fullwidthmedia(IPublishedContent content)
: base(content)
{ }
#pragma warning disable 0109 // new is redundant
public new static PublishedContentType GetModelContentType()
{
return PublishedContentType.Get(ModelItemType, ModelTypeAlias);
}
#pragma warning restore 0109
public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<Fullwidthmedia, TValue>> selector)
{
return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector);
}
you could add
@Helper RenderContent(IPublishedContent content) {
switch content.DocumentTypeAlias
{
case "Textelement":
@RenderContent((Textelement)content)
break;
case "Fullwidthmedia":
@RenderContent((Fullwidthmedia)content)
break;
}
}
RuntimeBinderException: The best overloaded method match for 'ASP._Page_Views_Masterk_cshtml.RenderContent(ASP.Textelement)' has some invalid arguments]
CallSite.Target(Closure , CallSite , _Page_Views_Master_cshtml , Object ) +169
ASP._Page_Views_Master_cshtml.Execute() in c:\inetpub\temp\DWASFiles\sites\f30ae816-949f-4021-a5a5-39b7a20a0adf\VirtualDirectory0\site\wwwroot\Views\Master.cshtml:14
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +113
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +290
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 filters, ActionResult actionResult) +52 System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult) +10System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +22System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9765121
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155