如何留住空间中的DropDownList - ASP.net MVC剃刀意见 [英] How to retain spaces in DropDownList - ASP.net MVC Razor views
问题描述
我结合我的模型以下列方式中的观点:
I'm binding my model in the following way in the view:
<%=Html.DropDownList("SelectedItem",new SelectList(Model.MyItems,"ItemId","ItemName")) %>
问题是我的项目的文本与词之间有空格的格式文本,如下图所示。
Issue is my item text is a formatted text with spaces in between words, as below.
#123 First $234.00
#123 AnotherItem $234.00
#123 Second $234.00
我要保留的空间在这个项目文本将其添加为DropDownList即使经过。但不幸的是我的DropDownList显示他们没有如下空间:
I want to retain the spaces in this item text even after they are added to DropDownList. But unfortunately my DropDownList shows them without spaces as below:
#123 First $234.00
#123 AnotherItem $234.00
#123 Second $234.00
当我查看该页面的源这些空间都完好无损,但显示事实并非如此。我试着加上' &放大器; NBSP;
而不是空格,但的SelectList(MVC框架类)内部的方法是使用HtmlEn $ C $之前将它们设为DropDownList的项目℃。
When I view the source of the page those spaces are intact but in display it is not. I've tried to add '
' instead of spaces but SelectList (MVC framework class) internal method is using HtmlEncode before adding them as items in the dropdownlist.
有没有什么办法可以做到这一点?
Is there any way I can achieve this?
推荐答案
NBSP在HTML相当于\\ XA0作为一个C#字符串,所以用这个来代替空格,当HTML EN $ C $光盘,它会产生NBSP
nbsp in html corresponds to "\xA0" as a C# string, so use this instead of spaces, when HTML encoded it will produce nbsp
这篇关于如何留住空间中的DropDownList - ASP.net MVC剃刀意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!