Map sitecore 8 general link field from Index

☆樱花仙子☆ 提交于 2019-12-13 01:18:09

问题


I am using sitecore content search API to get the general link field from sitecore index. Below is my model

public class GrantItem : BaseSearchItem
{
    [IndexField("grant_name")]
    public string GrantName { get; set; }

    [IndexField("grant_description")]
    public string GrantDescription { get; set; }

    [IndexField("grant_categories_sm")]
    public CategoryItem[] GrantCategories { get; set; }

    [IndexField("grant_status_s")]
    public CategoryItem GrantStatus { get; set; }

    [IndexField("grant_application_type_sm")]
    [TypeConverter(typeof(IndexFieldIDValueConverter))]
    public IEnumerable<ID> ApplicationType { get; set; }

    [IndexField("grant_url")]
    public string GrantURL { get; set; }
}

When I am using sitecore content search API. I am getting the following xml in the GrantURL.

 <link linktype=\"external\" url=\"http://www.google.com.au\" anchor=\"\"    
 target=\"\" /> 

Is there any default converter in sitecore to map this to a Link field or do I need to parse it manually or create a custom converter ?


回答1:


As far as I am aware there no type converters for this.

It's quite easy to create your own though. This blog post has code that worked for me and you just have to implement the ConvertFrom and ConvertTo methods

http://reasoncodeexample.com/2014/01/30/indexing-datetime-fields-sitecore-7-content-search/




回答2:


@foreach (var resultItem in Model.SearchRequest.SearchResults)
                            {
                                <tr>
                                    @{
                                        XmlDocument doc = new XmlDocument();
                                        doc.LoadXml(resultItem.CrossSiteUrl);
                                        XmlElement root = doc.DocumentElement;
                                        string path = String.Empty;
                                        string target = String.Empty;
                                        if (!string.IsNullOrEmpty(resultItem.CrossSiteUrl))
                                        {
                                            if (!string.IsNullOrEmpty(root.Attributes["url"].Value))
                                            {
                                                path = root.Attributes["url"].Value;
                                            }
                                            if (!string.IsNullOrEmpty(root.Attributes["target"].Value))
                                            {
                                                target = root.Attributes["target"].Value;
                                            }
                                        }
                                    }
                                    <td><a href="@path" target="@target">@resultItem.PageTitle</a></td>
                                    <td>@resultItem.DownloadTypeName</td>
                                    <td>@resultItem.ReleaseDate.ToShortDateString()</td>
                                    <td>@Convert.ToInt64(resultItem.FileSize).ConvertToSize()</td>
                                </tr>
                                <tr>
                                    <td colspan="4">@resultItem.ShortDescription</td>
                                </tr>
                            }


来源:https://stackoverflow.com/questions/32264224/map-sitecore-8-general-link-field-from-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!