asp.net – Glass Mapper打破了图像字段的标准值
发布时间:2020-05-24 15:23:22 所属栏目:asp.Net 来源:互联网
导读:考虑模板: 公司 徽标(图像字段) 公司名称(文本字段) 公司模板在两个字段上都设置了标准值.如果我们获取公司项目并使用Glass保存而不进行任何更改,则Logo字段不再使用标准值. (公司名称字段未触及.) 看起来,问题是Glass.Mapper.Sc.DataMappers.SitecoreFieldI
|
考虑模板: 公司 >徽标(图像字段) 公司模板在两个字段上都设置了标准值.如果我们获取公司项目并使用Glass保存而不进行任何更改,则Logo字段不再使用标准值. (公司名称字段未触及.) 看起来,问题是Glass.Mapper.Sc.DataMappers.SitecoreFieldImageMapper以不同于Sitecore的方式序列化该字段的值.当它试图保存时,它认为这是对字段的更改,不再使用标准值. 标准值: <image mediaid="{GUID}" />
玻璃生成的价值: <image height="64" width="64" mediaid="{GUID}" alt="Alt text" />
有没有办法让Glass生成与Sitecore相同的输出? 解决方法我认为问题在于 SitecoreFieldImageMapper如何将ImageField映射到Image.为了获得高度,宽度和Alt使用公共属性.如果我们通过反射器查看它们,我们将看到它的值不直接来自字段:public string Alt
{
get
{
string text = base.GetAttribute("alt");
if (text.Length == 0)
{
Item item = this.MediaItem;
if (item != null)
{
MediaItem mediaItem = item;
text = mediaItem.Alt;
if (text.Length == 0)
{
text = item["Alt"];
}
}
}
return text;
}
set
{
base.SetAttribute("alt",value);
}
}
如果字段不包含值(例如,对于“alt”:if(text.Length == 0)),则将从链接的MediaItem接收值.它导致在保存字段后从媒体库项添加高度,宽度和Alt. 要解决此问题,您可以尝试替换此代码: int height = 0; int.TryParse(field.Height,out height); int width = 0; int.TryParse(field.Width,out width); img.Alt = field.Alt; img.Height = height; img.Width = width; 直接获取属性而不是使用属性: int height = 0;
if(int.TryParse(field.GetAttribute("height"),out height))
{
img.Height = height;
}
int width = 0;
if(int.TryParse(field.GetAttribute("width"),out width))
{
img.Width = width;
}
img.Alt = field.GetAttribute("alt");
使用Alt属性一切都应该没问题.但是宽度和高度可能存在问题,因为它们不是Nullable,我不确定GlassMapper如何处理没有设置的宽度和高度的图像. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net http服务器推送到客户端
- asp.net – Jquery datepicker弹出窗口在IE8的选择日期没有
- asp.net – 以URL结尾的问题
- asp.net-mvc – 如何在ASP.NET MVC中生成完整的trace.axd?
- asp.net-mvc – 如何降级Visual Studio 2012中的Entity Fra
- Asp.NEt邮箱验证修改密码通过邮箱找回密码功能
- asp.net-mvc – Ninject.MVC3,将DependencyResolver传递给服
- asp.net – 如何使用横向方向将页面大小设置为信封大小?
- asp.net – 我们可以在网页中使用多种形式吗?
- 如果我的Asp.Net会话有IsNewSession == true,那我的意思是什
推荐文章
站长推荐
- 我可以使用ASP.NET Core仅针对.NET 4.6.1吗?
- asp.net-mvc – DropDownListFor在编辑视图上不重
- asp.net – 处理程序“PageHandlerFactory-ISAPI
- asp.net-mvc – MVC控制器操作参数为null
- 为什么asp.net会员资格有用户表和会员表?
- asp.net-mvc – 在ASP.Net MVC的视图中获取控制器
- asp.net-core – 如何使用带有IdentityServer4的
- asp.net-mvc – 使用ASP.NET MVC的IIS应用程序请
- asp.net – 如何在vNext项目中的方法上应用Outpu
- asp.net – 屏幕读者测试网站的可访问性
热点阅读
