Skip to content

Instantly share code, notes, and snippets.

@sebastiandammark
Last active May 10, 2017 18:49
Show Gist options
  • Select an option

  • Save sebastiandammark/e25ef34e3739ece2cfd71bc0a4218f36 to your computer and use it in GitHub Desktop.

Select an option

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

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