0

I have a list of alot of index that holds html tags like <input>, <select> and <td>. My problem is that when rendering those values, it just prints its normal values not as html tags:

Img: Where a part of that its render

  • Code:

    @foreach(var field in ViewBag.Fields) {

        @field
    }
    
  • I've tried this as well but both render the same:

    @foreach(var field in ViewBag.Fields)
    { 
    
        @Server.HtmlEncode(field);
    }
    
  • And

              @foreach(var field in ViewBag.Fields)
            { 
    
                @Html.Encode(field);
            }
    

But here the result:

Still not work

What should I do to make it work? Any suggestion?

3
  • 1
    Try something like this : stackoverflow.com/questions/1249018/… Commented Jun 5, 2013 at 20:40
  • 2
    @emd - MVC changed quite a bit since 2009. Commented Jun 5, 2013 at 20:43
  • Dont know why peope down voted. Commented Jun 5, 2013 at 20:43

1 Answer 1

6

You are HTML encoding the values - this is why you are getting them output as encoded HTML (this is also the safe default of razor).

Use the Raw helper to output HTML that is not encoded:

@Html.Raw(field);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.