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>
Replace(String, String) Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string.
The Java string replace() method will replace a character or substring with another character or string. The syntax for the replace() method is string_name. replace(old_string, new_string) with old_string being the substring you'd like to replace and new_string being the substring that will take its place.
Java String replace() MethodThe replace() method searches a string for a specified character, and returns a new string where the specified character(s) are replaced.
In MVC 3 output is encoded by default, so this should be enough:
@comic.name.Replace(" ", "-")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With