剃刀字符串替换
我正在寻找一种方法来进行某种字符串替换。
在这里找到了这个片段,但它给了我错误 MvcHtmlString is not Defined
:
@MvcHtmlString.Create(Html.Encode(comic.name).Replace(" ", "-"));
Whole Section Of Code:
@{
var comicName = UrlData[0];
var db = Database.Open("PhotoGallery");
var comics = db.Query(@"SELECT * FROM Comics WHERE name = @0", comicName).ToList();
Page.Title = comicName;
}
<div><a href="@Href("~/")">Home</a> -> <a href="@Href("~/Comics")">Comics Categories</a> -> <strong>@comicName</strong></div>
<div style="clear: both;"> </div>
<div class="sidebar">
<center><img src="@Href("~/Images/Comics", comicName + ".jpg")" title="@comicName" width="320" height="498" /><br />
@comics.Count Issue(s)</center>
</div>
<div class="main">
<h1>@comicName</h1>
@foreach (var comic in comics) {
@MvcHtmlString.Create(Html.Encode(comic.name).Replace(" ", "-"));
<ul class="thumbnails gallery">
<li class="gallery">
<a href="@Href("~/Comic/View", comic.name + " " + comic.issue)">
<img title="@comic.name #@comic.issue" src="@Href("~/Images/Comics", comicName + "/" + comic.issue + ".jpg")" class="thumbnail-no-border" width="200" height="200" />
<span class="below-image">@comic.name #@comic.issue</span>
<span class="image-overlay"><strong>@comic.pages Pages</strong></span>
</a>
</li>
</ul>
}
</div>
I was looking for a way to do some kind of string replace.
Found this snippet on here, but it gives me the error that MvcHtmlString is not defined
:
@MvcHtmlString.Create(Html.Encode(comic.name).Replace(" ", "-"));
Whole Section Of Code:
@{
var comicName = UrlData[0];
var db = Database.Open("PhotoGallery");
var comics = db.Query(@"SELECT * FROM Comics WHERE name = @0", comicName).ToList();
Page.Title = comicName;
}
<div><a href="@Href("~/")">Home</a> -> <a href="@Href("~/Comics")">Comics Categories</a> -> <strong>@comicName</strong></div>
<div style="clear: both;"> </div>
<div class="sidebar">
<center><img src="@Href("~/Images/Comics", comicName + ".jpg")" title="@comicName" width="320" height="498" /><br />
@comics.Count Issue(s)</center>
</div>
<div class="main">
<h1>@comicName</h1>
@foreach (var comic in comics) {
@MvcHtmlString.Create(Html.Encode(comic.name).Replace(" ", "-"));
<ul class="thumbnails gallery">
<li class="gallery">
<a href="@Href("~/Comic/View", comic.name + " " + comic.issue)">
<img title="@comic.name #@comic.issue" src="@Href("~/Images/Comics", comicName + "/" + comic.issue + ".jpg")" class="thumbnail-no-border" width="200" height="200" />
<span class="below-image">@comic.name #@comic.issue</span>
<span class="image-overlay"><strong>@comic.pages Pages</strong></span>
</a>
</li>
</ul>
}
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 MVC 3 中,输出默认进行编码,因此这应该足够了:
In MVC 3 output is encoded by default, so this should be enough: