Code stopped working after adding property converters
Hi Jeavon,
You said to post if I had a problem :)
I've found that my service alert code has stopped functioning.
This is the code:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
if ( Model.Content.HasProperty("serviceAlert") && Model.Content.HasValue("serviceAlert"))
{
@*
when we have service alerts they are stored as a string of comma seperated ids
so we split the string, then use the umbraco libraries to get a collection
of nodes for each valid (and visible) service id
*@
string serviceAlerts = Model.Content.GetPropertyValue<string>("serviceAlert");
var ids = serviceAlerts.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x));
var serviceAlertNodes = Umbraco.TypedContent(ids).Where(x => x != null && x.IsVisible());
if ( serviceAlerts.Any() )
{
foreach( var alert in serviceAlertNodes.Where(x => x.IsVisible()))
{
string alertType = alert.GetPropertyValue<string>("alertType");
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="servicealert alert alert-@alertType">
<h1>@alert.GetPropertyValue("title")</h1>
@Html.Raw(alert.GetPropertyValue<string>("bodyText"))
</div>
</div>
</div>
</div>
}
}
}
}
I get the following error:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 14:
Line 15: var ids = serviceAlerts.Split(new char[] { ',' },StringSplitOptions.RemoveEmptyEntries)
Line 16: .Select(x => int.Parse(x));
Line 17:
Line 18: var serviceAlertNodes = Umbraco.TypedContent(ids).Where(x => x != null && x.IsVisible());
I have tried the code and get the following error message :
Compiler Error Message: CS1061: 'object' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 6: var serviceAlerts = Model.Content.GetPropertyValue("serviceAlert");
Line 7:
Line 8: if (serviceAlerts.Any())
Line 9: {
Line 10: foreach (var alert in serviceAlerts.Where(x => x.IsVisible()))
Code stopped working after adding property converters
Hi Jeavon,
You said to post if I had a problem :)
I've found that my service alert code has stopped functioning.
This is the code:
I get the following error:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Thanks
Rich
Hi Rich,
I'm taking a guess that serviceAlert is a multinode tree picker, so now the hard is being done for you already by the converter:
Jeavon
Thanks Jeavon,
That's correct its an MNTP.
I have tried the code and get the following error message :
You need to specify the type on line 6
Ah yes think I get it now :
Thanks again :)
Great, any usage of the below property editors will need to be updated
IPublishedContent
IPublishedContent
IEnumerable<IPublishedContent> or IPublishedContent
IEnumerable<IPublishedContent>
RelatedLinks
Thanks again :)
is working on a reply...