In my view I am looping through my model and building html to display on the page. I am building this html with stringbuilder and if/else conditions.
I have tried to render this string as html but I keep getting stuck.
This is the code:
@model UserManager.Models.vw_UserManager_Model
<div id="success-message">
<fieldset>
<legend><b>@ViewData["Action"]</b> </legend>
<!-- User created -->
<div id="content">
@Html.Raw("some test string");
@{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int i = 0;
sb.Append("<ul>");
foreach (var item in Model)
{
string s = item.ToString();
if (s == "," && i != 1)
{
// When it finds first delimiter, start building the string
i = 1;
sb.Append("<li>");
}
else if (s == "," && i == 1)
{
// When it finds first delimiter, start building the string
sb.Append(" : ");
}
else if (i == 1 && s != "/")
{
// Contine building the string
sb.Append(s);
}
else if (s == "/")
{
// End current list item and set i to 0. This will start the next li sequence
sb.Append("</li>");
i = 0;
}
else
{
// Do nothing in the loop
}
}
sb.Append("</ul>");
var str = MvcHtmlString.Create(sb.ToString());
}
</div>
</fieldset>
</div>
Contents of SB
{<ul><li>firstname : sdlmsdm</li><li>lastname : smsd</li><li>salutation : Mr</li><li>password : ksklsd</li><li>email : [email protected]</li><li>userName : sdkmsdmke</li><li>MaxConcurrentUsers : 0</li><li>group_name : [PIAS] UK LTD</li><li>module_name : Connect:Top 1000 Advertisers</li><li>isactive : True</li><li>IsApproved : False</li><li>alf : True</li><li>brad : False</li><li>selected_moduleAlf : Connect:Top 1000 Advertisers : System.String : selected_moduleBrad : false : </ul>}
I can't see anything of the HTML once this code is finished debugging. Does anyone have the answer?