在ASP.NET MVC4中,我在我的表中動態生成<tr>
s。我正在這樣做,因此我可以根據模型中的變量應用不同的onclick
值。動態生成<tr> s導致ASP.NET崩潰
當我這樣做:
if(publication.ActionType == ActionType.NoticeOnly){
<tr onclick='$launchMyEman(this, 'NoticeOnly')'>
} // Visual Studio treats this line as text, note code
於是我就用Html.Encode()
爲周圍的工作。這裏是我當前的代碼:
if(publication.ActionType == ActionType.NoticeOnly){
@Html.Raw("<tr onclick='$launch(this, 'NoticeOnly')'>")
} else if (publication.ActionType == ActionType.ReadAndSign) {
@Html.Raw("<tr onclick='$launch(this, 'ReadAndSign')'>")
} else {
@Html.Raw("<tr onclick='$launch(this, 'ReadAndSignNotice')'>")
}
如果這一觀點被加載時,它會導致以下錯誤:
Encountered end tag "tr" with no matching start tag. Are your start/end tags properly balanced?
的</tr>
標籤自帶了很多<td>
年代以後。如果我刪除了上面的代碼並且放置了一個簡單的<tr>
它可以工作,所以錯誤肯定與上面的代碼有關。當我在視圖上放置一個斷點時,它永遠不會到達。它在運行時。
查看呈現html的視圖源並確保您遵循標準HTML –
我看不到呈現的HTML,我得到的只是一個Parser Error頁面。 –
當您真正需要在網頁上顯示<>字符時,應該進行編碼。你試圖放下HTML,所以你特別是*不*要編碼。 – Flater