Skip to content

Instantly share code, notes, and snippets.

@sebastiandammark
Last active May 10, 2017 18:49
Show Gist options
  • Save sebastiandammark/e25ef34e3739ece2cfd71bc0a4218f36 to your computer and use it in GitHub Desktop.
Save sebastiandammark/e25ef34e3739ece2cfd71bc0a4218f36 to your computer and use it in GitHub Desktop.
The best overloaded method match for 'ASP._Page_Views_Master_cshtml.RenderContent(ASP.Textelement)' has some invalid arguments
@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>
}
@sebastiandammark
Copy link
Author

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(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +52 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +173 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase1.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.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.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

@sebastiandammark
Copy link
Author

sebastiandammark commented May 10, 2017

/// <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);
	}

@sebastiandammark
Copy link
Author

/// <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);
	}

@skttl
Copy link

skttl commented May 10, 2017

you could add

@Helper RenderContent(IPublishedContent content) {
switch content.DocumentTypeAlias
{
case "Textelement":
@RenderContent((Textelement)content)
break;
case "Fullwidthmedia":
@RenderContent((Fullwidthmedia)content)
break;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment