Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6928345

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:10:31+00:00 2026-05-27T11:10:31+00:00

I have a variable within item.Name that contains the string It’s Tuesday!. To alleviate

  • 0

I have a variable within item.Name that contains the string “It’s Tuesday!”.
To alleviate javascript errors, in the c# controller I have already escaped this single quote.
On the webpage, it appears like this “It\’s Tuesday!”.

This at least prevents any javascript errors, however, I do not want the actual string displayed to contain the backslash that has escaped it.

How might I be able to revert the escaping once the javascript errors have already been taken care of? This feels like a rather simple problem, but I am a bit unfamiliar with MVC 3. Any hint is much appreciated! My searching did not find me any example specific to this.

An example of my code in the Razor View:

@foreach (var item in Model)
{ 
    @Html.DisplayFor(modelItem => item.Name) // item.Name = "It\'s Tuesday!"
} 
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:10:31+00:00Added an answer on May 27, 2026 at 11:10 am

    Create an extension method you can use or simply encode directly. I would not encode prior to the view getting it unless you have a separate property in your viewmodel meant for this (not a bad idea()

    This is not tested but something along these lines

    
    public static class HtmlExtensions
    
    {
        public static IHtmlString JavaScriptEncode(this HtmlHelper html, string item)
        {
            return new HtmlString(HttpUtility.JavaScriptStringEncode(item));
        }
    }
    
    

    You can then just call @Html.JavaScriptEncode(yourProperty) from the view or simply reference your encoded property name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class which represents a person, a variable within that class
I have a variable that contains a 4 byte, network-order IPv4 address (this was
I have a multidimensional array that contains a variable number of sub arrays. Each
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
I have a variable that is built in loop. Something like: $str = ;
I have an ArrayList that im populating within java and passing it off to
I am having a problem where I have made a database that contains 7
How do I manipulate textfield variables within an iPhone app? I want to have
I have variable @count of datatype int.I am setting values to this @count. I
How I can have variable number of parameters in my function in C++. Analog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.