在我看來,我循環瀏覽模型並生成html以顯示在頁面上。我正在用stringbuilder和if/else條件構建這個html。在MVC 3中渲染StringBuilder HTML查看
我試圖呈現這個字符串爲html,但我一直陷入困境。
這是代碼:
@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>
內容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>}
的,我不能看到HTML一旦該代碼調試完畢的東西。有沒有人有答案?
你的意思是調試後str是空的? – Sharun 2013-04-09 09:35:55
@slacker str不是空的,因爲在斷點上我有一個我用循環構建的HTML體。 – 2013-04-09 09:38:54
最後李標籤未關閉 – Sharun 2013-04-09 10:00:08