2012-11-27 78 views
1

我正在使用asp.net C#MVC jTemplate將公告集合綁定到我的視圖中的模板。 其中一條公告的描述中包含html字符串。我如何使用jTemplate呈現字符串作爲html使用jTemplate

現在的問題是如何使這個字符串當作HTML

我的看法是一樣

<textarea id="dashAnnoucement_Template" 
     data-template-name="dashAnnoucement_Template" class="hidden"> 
{#foreach $T as Announcement} 
    <li id='{$T.Announcement$iteration}'> 
    {#if !$().compare($T.Announcement.Category, 
      @Convert.ToInt32(UI.Entities.AnnouncementCategory.RichText))} 
     <div class="card large flipped"> 
     <div class="pic"> 
     {#if $T.Announcement.LinkOff} 
     {#if $T.Announcement.Image.IsVideo} 
      <a href="{$T.Announcement.LinkOff.Target}" class="play"> 
      <span>{$T.Announcement.Image.AltText}</span> 
      <img alt="{$T.Announcement.Image.AltText}" 
        src="{$T.Announcement.Image.Source}" class="thumb"/> 
      </a> 
     {#else} 
      <a href="{$T.Announcement.LinkOff.Target}"> 
      <img alt="" src="{$T.Announcement.Image.Source}" class="thumb"/> 
      </a> 
     {#/if} 
     {#else} 
     <img alt="" src="{$T.Announcement.Image.Source}" class="thumb"/>  
     {#/if}      
     </div> 
     <div class="content"><h3> 
     {#if $T.Announcement.LinkOff}     
     <a href="{$T.Announcement.LinkOff.Target}" 
      target="{#if $T.Announcement.LinkOff.IsExternal}_blank{#else}_self{#/if}"> 
      {$T.Announcement.Title}</a> 
     {#else}  
     {$T.Announcement.Title}       
     {#/if} 
     </h3> 
     <p>{$T.Announcement.Summary}</p> 
     </div> 
     </div> 
    {#else} 
     {$T.Announcement.Description} 
     @*Need to render this as html*@ 
    {#/if} 
    </li> 
{#/for} 
</textarea> 

jQuery代碼就像

$(Container).empty() 
      .setTemplateElement(Template) 
      .processTemplate(announcementsCollection); 

我的JSON數據即announcementsCollection就像

[ {  "Category": 1,  "Title": "White Space Announcement Title",  "Description": "",  "Summary": "Join us Fri,April 24 in Atlanta,GA to mingle with Solavei members & hear top earner success stories",  "Image": {  "Source": "http://slvdev.blob.core.windows.net/media/1463/whitespace_1.jpg",  "AltText": "",  "Target": "",  "IsVideo": false  },  "Date": "\/Date(-62135596800000)\/",  "LinkOff": {  "Target": "http://solavei.com/",  "Text": "Learn More >",  "IsExternal": true  } }, {  "Category": 1,  "Title": "Got Questions?",  "Description": "",  "Summary": "Access Member Support for information on your phone, your Solavei Membership, and your Solavei Mobile Service.",  "Image": {  "Source": "http://slvdev.blob.core.windows.net/media/7323/equipment-support-224x168.jpg",  "AltText": "",  "Target": "",  "IsVideo": false  },  "Date": "\/Date(-62135596800000)\/",  "LinkOff": {  "Target": "http://support.solavei.com",  "Text": "Learn More >",  "IsExternal": true  } }, {  "Category": 4,  "Title": "html",  "Description": "<div class=\"imageBox shadowBox\" style=\"float: right; margin: -20px -20px 0px 20px;\">           \t      <a target=\"_blank\" href=\"https://support-uat.solavei.com\">\t\t      \t\t      <img class=\"fullImage\" alt=\"\" src=\"http://slvdev.blob.core.windows.net/media/35985/neon.jpg\" style=\"height:170px\">\t      </a>                 </div>\n<div class=\"contents\">               <h2>             <a target=\"_blank\" href=\"https://support-uat.solavei.com\">             Rich text      </a>      </h2>                  <p>Access Member Support for information on your phone, your Solavei Membership, and your Solavei Mobile Service.</p>           </div>",  "Summary": "<div><img src='https://slvdev.blob.core.windows.net/media/35985/neon.jpg' wid/>\n<p>Test Message</p></div>",  "Date": "\/Date(-62135596800000)\/" } ] 

回答

0

我知道這是一箇舊帖子,但是,首先,您必須將您的JSon數據轉換爲Html代碼,然後使用 使用Html.Raw("")將代碼顯示爲Html

@Html.Raw("Your html in here") 
相關問題