2012-12-08 2 views
2

안녕하세요, MVC를 처음 사용하고 대체 색상 행을 표시하는 테이블을 만들려고합니다. 이런 식으로 뭔가 :MVC에서 HTML 렌더링 사용 안 함

@foreach (var item in Model) { 

var result = ""; 
var styleWhite = @"style=""background-color:white"""; 
var styleBlue = @"style=""background-color:blue"""; 

if ((item.ID % 1) == 0) 
{ result = styleBlue; } 
else 
{ result = styleWhite; } 

<tr @result > 
    <td> 
     @Html.DisplayFor(modelItem => item.CALLTYPE) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.DESCRIPTION) 
    </td> 
    <td> 
     @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | 
     @Html.ActionLink("Details", "Details", new { id=item.ID }) | 
     @Html.ActionLink("Delete", "Delete", new { id=item.ID }) 
    </td> 
</tr> 
} 

큰 따옴표이 같은 "& 따옴표"로 렌더링을 유지하지만 :

<tr style=&quot;background-color:blue&quot; > 

렌더링을 억제하고, 큰 따옴표 (또는 작은 따옴표)를 얻을 수있는 방법이 있나요 꼬리표 안에? 도움을 주셔서 감사합니다.

답변

3

기본적으로 면도기 엔진은 항상 HtmlEncodes 모든 문자열을 사용합니다. 당신이 사용을 무시해야하는 경우

@Html.Raw(result) 
0

답을 찾을 수 없습니다 또한

<tr @Html.Raw(result) > 

이 모드해야 2가 아닌 1

0

사용하는 대신 작은 따옴표 :

@foreach (var item in Model) { 

var result = string.Empty; 
var styleWhite = @"style='background-color:white'"; 
var styleBlue = @"style='background-color:blue'"; 

if ((item.ID % 1) == 0) 
{ result = styleBlue; } 
else 
{ result = styleWhite; } 

<tr @result > 
    <td> 
     @Html.DisplayFor(modelItem => item.CALLTYPE) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.DESCRIPTION) 
    </td> 
    <td> 
     @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | 
     @Html.ActionLink("Details", "Details", new { id=item.ID }) | 
     @Html.ActionLink("Delete", "Delete", new { id=item.ID }) 
    </td> 
</tr> 
} 
+1

답장을 보내 주셔서 감사하지만 "& 39"로 렌더링됩니다. @ Html.Raw가 아래처럼 작동하는 것 같습니다. – CyMark