What are the indent values ​​in a MultiSelectBox?

I'm having trouble indenting in the Razor MultiSelectBox.

It works fine when I manually write HTML:

<select name="testfoo123" multiple="multiple" size="15"> <option value="PARENT1">Parent</option> <option value="CHILD1">&nbsp;I am indented</option> <option value="CHILD2">&nbsp;I am indented</option> <option value="PARENT1">Parent2</option> <option value="CHILD1">&nbsp;I am indented</option> <option value="CHILD2">&nbsp;I am indented</option> </select> 

Razor's HTML helpers, however, literally display the previous inextricable space in the form. As expected, indentation characters for the indentation are completely ignored.

The code I use to create the multiple select block is as follows:

 @Html.ListBoxFor(model => mySelectedValues, new MultiSelectList(myValues), new { size = "15" }) 
+4
source share
2 answers

I have found a solution. First: multi-screen selection is probably not the best choice for a tree-based control, but I will leave this solution to the programmer.

Solution: Add a literal, non-breaking space character. They are not filtered, but the equivalent of HTML (as well as the usual space character).

 const char nonBreakingSpace = '\u00A0'; 

Prepare every child with this symbol. Using a separate list as an example:

 var sendMeToTheHtmlHelper = new List<String>(); foreach(String yourString in yourCollection) { // If this element is a child and needs indentation: sendMeToTheHtmlHelper.Add(nonBreakingSpace + location); // else just add as normal } 
+3
source

Built-in HTML helpers in both web pages and MVC automatically HTML encode all input values. I'm sure there is no way to get your script to work with the built-in helper.

Fortunately, however, all of the source code for these helpers is available on the CodePlex website as part of the MVC source code release . You can take a look at this source code and write your own helper that is better targeted to your indented script.

0
source

All Articles