简体   繁体   English

如何在Html.Encode()中使用html'title'属性?

[英]How do I use the html 'title' attribute with Html.Encode()?

I've been tryin to find an example of the syntax for getting an html 'title' for a string when using Html.Encode(). 我一直在尝试查找使用Html.Encode()时获取字符串的html“标题”的语法示例。 I want to display the full name in the mouseover title, if it's too long. 如果过长,我想在鼠标悬停标题中显示全名。

Is there a way to do this without wrapping the string in a < span >, ie 有没有一种方法可以将字符串不包装在<span>中,即

 <span title = "<%=Html.Encode(model.Name) %>">   //displays the full name on mouseover
 <%=Html.Encode(model.Name.Substring(0, 10))%>... //displays the name up to a max length
 </span>

Or should I just do it this way? 还是我应该这样做?

Thanks! 谢谢!

Without a containing element, where are you going to hang your title? 没有包含元素,您将在哪里悬挂标题?

So, yes, you should wrap it in an inline element like span 所以,是的,您应该将其包装在像span这样的内联元素中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM