Are you still using uComponents? If so, check if you have the "uComponents.Legacy.dll" in your /bin folder. If so, then you could do this:
namespace Our.Umbraco
{
using uComponents.Core.DataTypes.MultipleTextstring; // for v4.x
// using uComponents.DataTypes.MultipleTextstring; // for v5.x
using umbraco.editorControls;
using umbraco.MacroEngines;
[RazorDataTypeModel(DataTypeGuids.MultipleTextstringId)]
public class MyMultipleTextstringModelBinder : MultipleTextstringModelBinder
{
}
}
Copy-n-paste that into a separate C# class (either drop it into your /App_Code folder - or if you already have other compiled code, put it in there)
What this does is convert the Multiple Textstring into a list of strings. Then you can use it in your Razor scripts, like so:
@foreach(var t in f.GetProperty("caption").Value)
{
<h1>@Library.StripHtml(t)</h1>
}
using System.Collections.Generic;
using System.Xml;
using umbraco.MacroEngines;
namespace Our.Umbraco
{
[RazorDataTypeModel(DataTypeGuids.MultipleTextstringId)]
public class MultipleTextstringModelBinder : IRazorDataTypeModel
{
public bool Init(int CurrentNodeId, string PropertyData, out object instance)
{
var values = new List<string>();
if (!string.IsNullOrEmpty(PropertyData))
{
var xml = new XmlDocument();
xml.LoadXml(PropertyData);
foreach (XmlNode node in xml.SelectNodes("/values/value"))
{
values.Add(node.InnerText);
}
}
instance = values;
return true;
}
}
}
Do keep in mind that if you use this code, it will convert all of your Multiple Textstring values into a proper strongly-typed model. :-)
@foreach(var t in f.GetProperty("sliderImageCaption").Value){ @Library.StripHtml(f.GetProperty("sliderImageCaption").Value) }
Output t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2
Instead of t1 t2
and if i change it to @Library.StripHtml(t) i get some errors while saving
error CS1502: The best overloaded method match for 'umbraco.MacroEngines.Library.RazorLibraryCore.StripHtml(System.Web.IHtmlString)' has some invalid arguments
Am basically using this in a javascript. When removing the symbol * for the split to work i get this
@foreach(var t in f.GetProperty("sliderImageCaption").Value.Split("*".ToCharArray())){ <h1>@Library.StripHtml(f.GetProperty("sliderImageCaption").Value)</h1> }
output
<h1>t 1 *t 2</h1> <h1>t 1 *t 2</h1>
And if i use this
@foreach(var t in f.GetProperty("sliderImageCaption").Value.Split("*".ToCharArray())){ <h1>@Library.StripHtml(t)</h1>
I'm assuming that you now have the model binding code in place? If so, then you don't need to split the string yourself - that will already be done for you.
So this should work...
@foreach(var item in f.GetProperty("caption").Value)
{
<h1>@item </h1>
}
If that doesn't work - then I'm not sure what the answer is. :-(
Slipt Multiple Text String
Hi ,
I have a multiple textString in v4.9.1 where i use * as symbol to split the content of each textString.
So far it works well but when view the source i realised the output also added this
Hi Fuji,
Are you still using uComponents? If so, check if you have the "uComponents.Legacy.dll" in your /bin folder. If so, then you could do this:
Copy-n-paste that into a separate C# class (either drop it into your /App_Code folder - or if you already have other compiled code, put it in there)
What this does is convert the Multiple Textstring into a list of strings. Then you can use it in your Razor scripts, like so:
Cheers, Lee.
Hi Lee,
No am using the custom Multiple TextString in v4.9.1. So i just need to make use of the namespace uComponents ? or do i need to install uComponents?
Hi Fuji,
No problem - don't worry about installing uComponents :-)
You can add in the custom Razor Model Binder code (from uComponents) https://ucomponents.codeplex.com/SourceControl/latest#uComponents.Legacy/DataTypes/MultipleTextstring/MultipleTextstringModelBinder.cs
Do keep in mind that if you use this code, it will convert all of your Multiple Textstring values into a proper strongly-typed model. :-)
Cheers, Lee.
Any Specific naming convention for this Lee ?? Or i just drop it in my App_code folder ?
Thanks
Just call it "MultipleTextstringModelBinder.cs" and drop it in your /App_Code folder.
Cheers, Lee.
Hmm, Am getting an ugly server error though
Ah, change it to:
Thanks Lee but still not working though
This
and if i change it to @Library.StripHtml(t) i get some errors while saving
Could try removing the @Library.StripHtml? (I'm not sure what it is expecting for an input)
Am basically using this in a javascript. When removing the symbol * for the split to work i get this
output
And if i use this
But am looking for and output like
Hi Fuji,
I'm assuming that you now have the model binding code in place? If so, then you don't need to split the string yourself - that will already be done for you.
So this should work...
If that doesn't work - then I'm not sure what the answer is. :-(
Nope this output :(
Hmm... doesn't seem like the model-binder code is working. :-(
Let me find some code which might help :-)
I found this other forum post about using Multiple Textstring values with Razor... quite a few code snippets in there:
http://our.umbraco.org/forum/developers/razor/21753-@foreach-value-of-Multiple-Textstring-uComponents-
Ive tried those as well!!
But here am using DynamicNode. Forgot to mention if a down make use of the Split * in the TextString it doesnt split up.
is working on a reply...