Results 1 to 3 of 3

Thread: [RESOLVED] pass html into razor.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Location
    Out there somewhere!
    Posts
    386

    Resolved [RESOLVED] pass html into razor.

    Hello

    I am new to the whole MVC/Razor style of coding.

    I am trying to pass a string to a cshtml file. The string is html. how can I do this. Here is the code -

    Code:
    @{
        ViewBag.Title = Model.Title;
    }
    
    @{
        @Model.CVBuilderInformation
    }
    And

    Code:
    model.CVBuilderInformation =
                "<p>The Personal Professional Profile can be used to record information about your career, your education and your professional development and achievements in both work and personal life.</p> <a href="http://www.soemthing.co.uk"
                    target="_blank">www.something.co.uk</a>
    I did it this way as the above text is not always shown. But when I run it puts the text out as a string, not html. Can you do that?

    Thanks

    Kev.

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: pass html into razor.

    C# Razor Syntax Quick Reference
    Code:
    @Html.Raw()
    Don't forget that generating raw HTML from the Controller could leave you open to potential XSS attacks.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Location
    Out there somewhere!
    Posts
    386

    Re: pass html into razor.

    Thanks for that. Worked like a dream.

    Kev.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width