我剛剛開始使用MVC,並試圖構建一個樣本,用於與jquery-mobile進行mvc交互的概念頁面證明。我已經在這方面尋找答案,但我認爲我還沒有足夠的知識來制定正確的查詢。mvc + jqm actionlink html text issue
對我的看法,我想生成輸出的功能就像這樣(從JQM演示現場採樣):
<ul data-role="listview" data-inset="true">
<li><a href="index.html">
<h3>Stephen Weber</h3>
<p><strong>You've been invited to a meeting at Filament Group in Boston, MA</strong></p>
<p>Hey Stephen, if you're available at 10am tomorrow, we've got a meeting with the jQuery team.</p>
<p class="ui-li-aside"><strong>6:24</strong>PM</p>
</a></li>
<li><a href="index.html">
<h3>jQuery Team</h3>
<p><strong>Boston Conference Planning</strong></p>
<p>In preparation for the upcoming conference in Boston, we need to start gathering a list of sponsors and speakers.</p>
<p class="ui-li-aside"><strong>9:18</strong>AM</p>
</a></li>
</ul>
所以,我喜歡這個工作吧:
@foreach (var item in Model) {
<li>
@Html.ActionLink(LargeExpandedMultiContentText, "Edit", new { id = item.SysID })
</li>
}
我的問題,我不知道一個簡單的方法問,是,如何,在MVC術語中,我應該填充變量,以便由ActionLink()生成的href匹配我從jqm網站採樣的樣式?
我試過這個,雖然它幾乎可以工作,但我確定它不是'正確'的方法,特別是當我得到一個拉動「史蒂文韋伯」和其他字符串的項目/模型...加上它編碼的文本,但我敢肯定有一種方法來處理這麼簡單。
@foreach (var item in Model) {
<li>
@{ String txt = "<h3>Stephen Weber</h3><p><strong>You've been invited to a meeting at Filament Group in Boston, MA</strong></p><p>Hey Stephen, if you're available at 10am tomorrow, we've got a meeting with the jQuery team.</p> <p class=\"ui-li-aside\"><strong>6:24</strong>PM</p>";
}
@Html.ActionLink(txt, "Edit", new { id = item.SysID })
</li>
}
謝謝,我感謝您的幫助
布賴恩
感謝@ Html.Raw暗示......我知道我看到什麼地方......你能回答,不管怎樣,問題的關於做一個嵌套的代碼塊withing在foreach部分? – reidLinden 2012-04-30 12:53:32
如果可以,很樂意幫忙,但請重申問題的嵌套代碼塊部分。我不確定你指的是什麼。 – DMulligan 2012-04-30 16:25:47
在我原來的帖子,第三代碼塊...在foreach中,我想知道如果這是正確的方式來處理這種想法,txt變量,並且如果這減少我字符串連接來構建出html ,或者如果有更多的MVC方式......爲了記錄,我將所有的代碼都翻譯成了你的推薦內容,而且事情看起來很隆重......謝謝! – reidLinden 2012-04-30 17:23:07