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

  • Home
  • SEARCH
  • 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 7842937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:26:07+00:00 2026-06-02T16:26:07+00:00

I am creating a MVC-Project. Using MVC 4 and Razor. After building some pages

  • 0

I am creating a MVC-Project. Using MVC 4 and Razor. After building some pages I was wondering: what is the difference between

MvcHtmlString.Create()

and

Html.Raw()

Would be nice if you could help me here to understand that.

Thanks in advance!

  • 1 1 Answer
  • 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-06-02T16:26:08+00:00Added an answer on June 2, 2026 at 4:26 pm

    This is an excellent opportunity to look at the source code that’s available to us for ASP.NET (https://github.com/aspnet/AspNetWebStack/).

    Looking at HtmlHelper.cs, this is the code for Html.Raw():

    public IHtmlString Raw(string value)
    {
        return new HtmlString(value);
    }
    
    public IHtmlString Raw(object value)
    {
        return new HtmlString(value == null ? null : value.ToString());
    }
    

    And this is the code for the MvcHtmlString class:

    namespace System.Web.Mvc
    {
        public sealed class MvcHtmlString : HtmlString
        {
            [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "MvcHtmlString is immutable")]
            public static readonly MvcHtmlString Empty = Create(String.Empty);
    
            private readonly string _value;
    
            public MvcHtmlString(string value)
                : base(value ?? String.Empty)
            {
                _value = value ?? String.Empty;
            }
    
            public static MvcHtmlString Create(string value)
            {
                return new MvcHtmlString(value);
            }
    
            public static bool IsNullOrEmpty(MvcHtmlString value)
            {
                return (value == null || value._value.Length == 0);
            }
        }
    }
    

    The most significant difference is that Html.Raw() accepts any object, while MvcHtmlString.Create() only accepts strings.
    Also, Html.Raw() returns an interface, while the Create method returns an MvcHtmlString object.
    Lastly, the Create deals with null differently.

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

Sidebar

Related Questions

Using MVC 2 I have been trying to make this record store project. Creating
new to asp.net mvc (using v3 + razor) and am wondering how to best
I am working on an MVC application using Entity Framework. After creating an EDMX,
I am creating a project using ASP.NET MVC. I want to show content of
I'm looking at creating my first ASP.NET MVC application using MVC3. The project template
I am new to Subsonic3. Want to create a project using MVC and subsonic
I have a project using ASP.Net MVC 3 and now I'm creating a report
When creating an empty MVC 2 project, I have a lot of javascript files
I am creating a very simple forum as my first MVC project. My database
I'm trying to create a many-to-many relationship using EF code first in my MVC

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.