2011-07-28 19 views
3

私のサイトにはかなりのコンテンツページがあります。それらのほとんどは純粋にテキストですが、一部にはリンクや類似のものが含まれています。 私はページの本体を格納し、私は一般的なContentModelにポストのコンテンツをロードwebrequestsを使用して、私のバックエンド-CMSとしてのワードプレスを使用しています:Parse Rarzor Html Helper from external .cshtml

public class WordPressPostModel 
{ 
    public string Title; 
    public string Content; 
    public string postId; 
    public string slug; 
    public string lang; 
    public string CategorySlug; 
    public DateTime CacheDate = new DateTime(); 
    public bool NotFound = true; 

    public WordPressPostModel() 
    { 

    } 
} 

素晴らしいだろう私は何を扱うことができればですコンテンツは、(部分的な)cshtmlビューとして取得され、ActionLinksや他のHTMLヘルパーがレンダリングされます。これを行う方法はありますか? RazorEngineを使用して

SOLUTIONダーリンは示唆されているように:

をカミソリエンジンはHTMLヘルパーをサポートしていないとして、あなたは、例えば、カスタムテンプレートベースの内側からそれらを呼び出すことにより、この問題を回避する必要があります

public abstract class MyCustomTemplateBase<T> : TemplateBase<T> 
{ 

    public string ActionLink(string linkText, string actionName, string controllerName) 
    { 
     string link = HtmlHelper.GenerateLink(HttpContext.Current.Request.RequestContext, RouteTable.Routes, linkText, "Default", actionName, controllerName, null, null); 
     return link; 
    } 
} 

そして、このようにそれを使用する:あなたはRazorEngineを見ても

Razor.SetTemplateBase(typeof(MyCustomTemplateBase<>)); 
    string raw = HttpUtility.HtmlDecode(Content);   
    string result = Razor.Parse(raw, this); 

答えて

3

+0

ありがとうございました! – AyKarsi