剃刀字符串替换

发布于 2024-11-17 23:39:00 字数 1683 浏览 4 评论 0原文

我正在寻找一种方法来进行某种字符串替换。

在这里找到了这个片段,但它给了我错误 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;">&nbsp;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶气 2024-11-24 23:39:00

在 MVC 3 中,输出默认进行编码,因此这应该足够了:

@comic.name.Replace(" ", "-")

In MVC 3 output is encoded by default, so this should be enough:

@comic.name.Replace(" ", "-")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文