반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

개발꿈나무

[Blazor] HTML Tag Encoding 본문

C#/Blazor

[Blazor] HTML Tag Encoding

HYOKYE0NG 2021. 12. 9. 08:13
반응형

DB에 string으로 저장되어 있는 HTML 코드를 태그 처리해서 출력하는 게 내 임무

보통 <p href="HTML CODE">TEST</p> 이렇게 하면

TEST라는 문자에 HTML 코드가 태그처리되서 출력되는데

Blazor에서는 태그가 전혀 적용되지 않았다.

 

Blazor에서 HTML code를 태그 처리하는 방법을 알아보니 다음과 같이 하면 된단다.

var markupstring = new MarkupString(vpm_detail.STANDARD_NO);

 

아래의 페이지를 참고했다.

 

Rendering raw/unescaped HTML in Blazor - Gérald Barré

In this post, I describe how to render a string that contains HTML elements in an ASP.NET Core Blazor component.

www.meziantou.net

 

Telerik Grid의 컬럼에 HTML 태그를 집어넣는 코드는 다음과 같다.

<GridColumn Field="DRAWING.VIEW_DWG" Title="View DWG" Lockable="true" Width="100px">
	<Template>
	@{ 
		var data = context as DRAWING_INDEX_MODEL;
        var markup_viewdwg = new MarkupString(data.DRAWING.VIEW_DWG);
        @markup_viewdwg
    }
    </Template>
</GridColumn>

 

 

추가적으로,

HTML TAG 처리가 잘 되지 않았던 부분이 있었다.

바로 DB 데이터에 '&' 연산자 대신 '%26'이 위치해있던 경우!

&nbsp; 대신 %26nbsp;로 되어있었다.

 

%26을 ASCII CODE로 표현하면 & 연산자이다.

아래 사이트에 URL Encoding 표가 잘 정리되어 있다.

 

HTML Charset

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

따라서 나는 REPLACE 함수를 이용하여 DB안의 %26을 모두 & 연산자로 수정해주었다.

반응형
Comments