I just downloaded the external package Link Picker and I am trying to use in in a partial view but am having a difficult time.
Here is the code for my Partial:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var pills = Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("aboutPanel"));
int _s2 = 2;
int _s4 = 4;
int _s2count = 0;
int _s4count = 0;
<div class="container-fluid no-side-padding" style="padding-top: 20px;">
<div class="container">
<div class="row">
@foreach (var pill in pills)
{
_s2count++;
_s4count++;
// This is where the Link Picker URL needs to go
<div class="col-sm-6 col-md-3 col-lg-3 about-us-panel" onclick="location='@pill["panelURL"]';">
<div class="hovereffect img-rounded">
<img class="img-responsive img-about img-rounded" src="@Umbraco.Media(pill["aboutImage"].ToString()).Url" />
<div class="overlay img-rounded"><h2>@pill["panelTitle"]</h2></div>
</div>
<div class="clearfix"></div>
</div>
if (_s2count == _s2 && _s4count == _s4)
{
_s2count = 0;
_s4count = 0;
<div class="clearfix visible-sm visible-md visible-lg"></div>
}
else if (_s2count == _s2)
{
_s2count = 0;
<div class="clearfix visible-sm"></div>
}
}
</div>
</div>
</div>
}
The problem I have is Link Picker returns json and I am not too sure how to access the "url', "name", "target" properties of Link Picker.
The instructions use CurrentPage as an example and use the following syntax:
@CurrentPage.LinkPickerName.url
This does not work for me as I access the document type properties like this:
@pill["datatype"]
I have tried a number of different combinations but all are fruitless. I even tried DeSerializing the JSON object into dynamic but was getting some null errors.
public class LinkPickerModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string Target { get; set; }
public string Hashtarget { get; set; }
}
And after that you will be able to use deserialization:
var linkPicker = JsonConvert.DeserializeObject<LinkPickerModel>(block.GetPropertyValue<string>("link"));
if (linkPicker != null)
{
<a href="@linkPicker.Url" target="@linkPicker.Target" class="link">@linkPicker.Name<span></span></a>
}
But really the project could do with writing a property value converter so the conversion is done automatically. Should be relatively simple to write one.
The Github readme https://github.com/Gibe/Umbraco-Link-Picker/blob/master/README.md is mentioning exactly what Alex suggest. But the package could include the compiled assembly, with use of PropertyValueConverter and the model, so you just need to add e.g. using Gibe.LinkPicker.Models.. Like in Archetype where you add using Archetype.Models and using Archetype.Extensions
Thanks for everyone help. This is what I ended up doing.
public class LinkPickerModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string Target { get; set; }
public string Hashtarget { get; set; }
public LinkPickerModel ReturnModel(string JsonObject)
{
var linkpicker = JsonConvert.DeserializeObject<LinkPickerModel>(JsonObject);
return (LinkPickerModel)linkpicker;
}
}
The Partial View:
LinkPickerModel ipm;
foreach (var pill in pills)
{
lpm = new LinkPickerModel().ReturnModel(pill["panelURL"].ToString());
}
<div>@lpm.Url</div>
Link Picker in a Partial View.
I just downloaded the external package Link Picker and I am trying to use in in a partial view but am having a difficult time.
Here is the code for my Partial:
The problem I have is Link Picker returns json and I am not too sure how to access the "url', "name", "target" properties of Link Picker.
The instructions use CurrentPage as an example and use the following syntax:
This does not work for me as I access the document type properties like this:
I have tried a number of different combinations but all are fruitless. I even tried DeSerializing the JSON object into dynamic but was getting some null errors.
HELP!!!!
Any suggestions?
Hi Phillip,
Try to add new class to your solution -
And after that you will be able to use deserialization:
Cheers
There's more instructions on the GitHub site: https://github.com/Gibe/Umbraco-Link-Picker
But really the project could do with writing a property value converter so the conversion is done automatically. Should be relatively simple to write one.
I looked up the GitHub details. Not too much help. I will Alex's suggestion.
The Github readme https://github.com/Gibe/Umbraco-Link-Picker/blob/master/README.md is mentioning exactly what Alex suggest. But the package could include the compiled assembly, with use of PropertyValueConverter and the model, so you just need to add e.g. using Gibe.LinkPicker.Models.. Like in Archetype where you add using Archetype.Models and using Archetype.Extensions
/Bjarne
Thanks for everyone help. This is what I ended up doing.
The Partial View:
Great Phillip !
is working on a reply...