Error226'Umbraco.Web.Models.PartialViewMacroModel' does not contain a definition for 'mediaArticleLink' and no extension method 'mediaArticleLink' accepting a first argument of type 'Umbraco.Web.Models.PartialViewMacroModel' could be found (are you missing a using directive or an assembly reference?)
create a c# class in app_code or if you have your website as web application you can put the below file into any folder you want. (remember to build the solution after adding this class)
using System.Collections.Generic;
using System.Web;
using uComponents.DataTypes.MultiUrlPicker.Dto;
using uComponents.DataTypes.UrlPicker;
using uComponents.DataTypes.UrlPicker.Dto;
/// <summary>
/// Global functions static partial class
/// </summary>
public static partial class GlobalFunctions
{
public static class uComponents
{
#region uComponent extensions
public static IHtmlString GetUrlPickerAsLinkTag(string urlPickerState, string cssClass = "", string anchorLink = "", string iconCssClass = "")
{
var urlPicker = UrlPickerState.Deserialize(urlPickerState);
if (string.IsNullOrWhiteSpace(urlPickerState) || urlPicker.Url == null)
{
return new HtmlString(string.Empty);
}
return GetUrlPickerAsLinkTag(urlPicker, cssClass, anchorLink, iconCssClass);
}
public static IHtmlString GetUrlPickerAsLinkTag(UrlPickerState urlPicker, string cssClass = "", string anchorLink = "", string iconCssClass = "")
{
cssClass = string.IsNullOrEmpty(cssClass) ? string.Empty : "class=\"" + cssClass + "\"";
var newWindow = urlPicker.NewWindow ? "target=\"_blank\"" : string.Empty;
// If external url and not null
if (urlPicker.Mode == UrlPickerMode.URL)
{
// If without "http://" then add it
if (!urlPicker.Url.ToLower().StartsWith("http://"))
{
urlPicker.Url = "http://" + urlPicker.Url;
}
}
if (!string.IsNullOrWhiteSpace(anchorLink))
{
urlPicker.Url = "#" + anchorLink;
}
if (!string.IsNullOrWhiteSpace(iconCssClass))
{
iconCssClass = string.Format("<span class=\"{0}\"></span>", iconCssClass);
}
return
new HtmlString(
string.Format(
"<a href=\"{0}\" {1} {2}>{3}{4}</a>", urlPicker.Url, cssClass, newWindow, urlPicker.Title, iconCssClass));
}
public static MultiUrlPickerState ConvertMultiUrlPickerToList(string multiUrlPicker)
{
return MultiUrlPickerState.Deserialize(multiUrlPicker);
}
#endregion
}
}
oh man, so it's not complaining about url, it's the title.
because the title is called link-title and a field doesn't accept dash (in c#) so you have to get it like this:
In a tweet, Lee Kelleher stated that the uComponents Link Picker will be added to the Umbraco Core. I hope there will be some documentation about it then.
How to work with the Urlpicker datatype in razor
Hi,
I'm trying to display the url from the urlpicker datatype, but no luck so far. Does somebody know how to call the url with razor?
@item.partnerUrl
generates
URL,True,,http://www.domain.tld,link
kris,
i recently did it and i have
@if (Model.usefulLinks.ToString() != string.Empty)
{
<ul>
@foreach (var item in Model.usefulLinks.BaseElement.Elements("link"))
{
if (item.Attribute("type").Value == "internal")
{
<li><a href="@umbraco.library.NiceUrl(int.Parse(item.Attribute("link").Value))">@item.Attribute("title").Value</a></li>
}
else {
<li><a href="@item.Attribute("link").Value" rel="external">@item.Attribute("title").Value</a></li>
}
}
</ul>
}
Regards
Ismail
Has anyone yet used the uComponent Url Picker with v6 Razor
I'm trying this:
@Model.Content.GetProperty("mediaArticleLink").Url
But I'm getting this error by VS:
Error226'Umbraco.Web.Models.PartialViewMacroModel' does not contain a definition for 'mediaArticleLink' and no extension method 'mediaArticleLink' accepting a first argument of type 'Umbraco.Web.Models.PartialViewMacroModel' could be found (are you missing a using directive or an assembly reference?)
Thanks for your help,
Anthony
create a c# class in app_code or if you have your website as web application you can put the below file into any folder you want. (remember to build the solution after adding this class)
then within the page call it like this:
this is a very generic class which can be used in any solution/project and that's what I do almost in all the projects.
hope this will help you all.
I know there might be some shorter code but the above code will cover every scenario including Multi Url Picker.
Hi Ali,
Thanks again for the code. This does indeed seem a lot of code just to get some values out of the uComponents Url Picker.
Eric Schrepel suggested this:
but I tried that, and it doesn't seem to work in v6 Razor (see my post)
greetings,
Anthony
@Ali,
I used to get my values out of the Url Picker like this:
if (Model.mediaArticleLink.Title != null)
{
<a href="@Model.mediaArticleLink.Url" title="@Model.mediaArticleLink.Title" target="_blank">
@Model.mediaArticleLink.Title
</a>
}
else{
<a href="@Model.mediaArticleLink.Url" target="_blank">@Model.mediaArticleLink.Url</a>
}
but this doesn't seem to work anymore in v6 Razor
with Umbraco 6 you cannot use model as it is strongly Typed so you need to use CurrentPage which is dynamic
Yeah, I already tried that, but then I'm getting a RuntimeBinderException:
"Umbraco.Core.Dynamics.DynamicXml' does not contain a definition for 'Title"
I am assuming that your property alias is mediaArticleLink
so now try this:
does'nt work, I checked
var myUrlPicker = CurrentPage.urlPicker.First;
in the debugger and it doesn't generate an error but it also doesn't return anything. myUrlPicker is just an empty variable.
i've updated the code, is urlPicker your property alias?
if yes ,it is so odd I've tried the above code and it works fine on umbraco 6.0.5.
could you tell me which version of umbraco you are using?
the property alias is:
mediaArticleLink
my Umbraco version is 6.1.5
I'm using the MVC mode
are you using xml mode or csv?
the Data mode is xml
I think that's the problem is there any chance you could convert it to CSV?
try this
url has to be small case not capital. and you dont need to change xml to csv
I changed the datatype configuration to CSV mode, but that didn't solve it.
The link I stored with the Url Picker looks like this in umbraco.config
<mediaArticleLink>
<url-picker mode="URL">
<new-window>False</new-window>
<node-id />
<url>www.umbraco.com</url>
<link-title>testlink</link-title>
</url-picker>
</mediaArticleLink>
alas, @CurrentPage.mediaArticleLInk.url isn't working either
it is so odd, I've just tried that with xml mode on umbraco 6.1.5 and it worked fine.
are you sure you are not missing anything? what error do you get?
when I run this code:
<a href="@CurrentPage.mediaArticleLink.url" title="@CurrentPage.mediaArticleLink.title" target="_blank">
@CurrentPage.mediaArticleLink.title
</a>
I get a RuntimeBinderException:
'Umbraco.Core.Dynamics.DynamicXml' does not contain a definition for 'title'
mystery solved, I ran this code:
<a href="@CurrentPage.mediaArticleLink.url" title="" target="_blank">
@CurrentPage.mediaArticleLink.url
</a>
and now the link is showing.
So it was @CurrentPage.mediaArticleLink.title that was generating the error.
oh man, so it's not complaining about url, it's the title. because the title is called link-title and a field doesn't accept dash (in c#) so you have to get it like this:
I am sure this is your answer
Indeed
worked!
Thanks a lot for your patience.
In a tweet, Lee Kelleher stated that the uComponents Link Picker will be added to the Umbraco Core. I hope there will be some documentation about it then.
have a nice weekend,
Anthony
Is there anyway you could mark it as solution?
have a great weekend.
for everyone struggling with the same issue, this was the solution:
<a href="@CurrentPage.mediaArticleLink.url" title="@CurrentPage.mediaArticleLink.XPath("//link-title").InnerText" target="_blank">
@CurrentPage.mediaArticleLink.XPath("//link-title").InnerText
</a>
With lot's of thanks and appreciation to Ali Sheikh Taheri for his help and patience!
is working on a reply...