2011-07-28 3 views
3

내 사이트에는 많은 콘텐츠 페이지가 있습니다. 그들 대부분은 순전히 텍스트이지만 일부는 링크와 비슷한 것들을 포함합니다. 나는 일반적인 ContentModel으로 게시물의 내용을로드 내가 페이지의 몸에 저장 내 백엔드-CMS로 워드 프레스를 사용하고 webrequests을 사용하고 있습니다 :Parse Rarzor Html Helper from .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 Helpers를 렌더링 한 컨텐트. 이것을 할 수있는 방법이 있습니까? 면도기 엔진은 예를 들어, 사용자 지정 서식 기지 내부에서 그들을 호출하여이 해결해야 할 HTML 도우미를 지원하지 않습니다

으로 : 대린 제안으로 RazorEngine를 사용

솔루션

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; 
    } 
} 

그리고는 다음과 같이 사용 :

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

답변

3

당신은 RazorEngine 한 번 봐 걸릴 수 있습니다.

+0

감사합니다. – AyKarsi