Solved

MVC4 Html.Raw not working

Posted on 2013-06-26
6
1,039 Views
Last Modified: 2013-06-26
Hi:

I have an app that has the questions and answers to FAQs stored as raw html in a SQL Server Database

In other cases, I've been able to display the formatted Html in my apps by using Html.Raw instead of Html.DisplayFor

However, in the following code which uses Bootstrap:

@model Site.Models.FaqsViewModel

<div class="content">
    <div class="row">
        <div class="accordion" id="accordion2">
            <div class="accordion-group">

                @foreach (var item in Model.FaqBriefs)
                {
                    <div class="accordion-heading">
                        <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href= @Html.DisplayFor(modelItem => item.AnswerLink)>@Html.DisplayFor(modelItem => item.Question)</a>
                    </div>
                    <div id=@Html.DisplayFor(modelItem => item.AnswerId) class="accordion-body collapse ">
                        <div class="accordion-inner">
                            @Html.Raw(modelItem => item.Answer)
                        </div>
                    </div>
                }

            </div>

        </div>
    </div>
</div>

Open in new window


the line @Html.Raw(modelItem =>item.Answer) is giving me the error that "Cannot resolve method Raw(lamda expression)  in the intellisense and " Cannot convert lambda expression to type 'string' because it is not a delegate type" when I run it.  

Any help in figuring this out greatly appreciated.

RBS
0
Comment
Question by:RBS
  • 3
  • 3
6 Comments
 
LVL 11

Accepted Solution

by:
lenordiste earned 500 total points
ID: 39278811
try this:
@Html.Raw(@item.Answer)

Open in new window

0
 

Author Closing Comment

by:RBS
ID: 39278825
Perfect, thank you!

ps - I'm wondering why I'm using lamda expressions in the other parts of the code - it's just a patter that I've picked up as I learn this stuff?
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 39278863
well, I think I can't explain it better than this guy:
http://stackoverflow.com/questions/9465376/when-should-i-use-html-displayfor-in-mvc
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:RBS
ID: 39278876
Excellent - Now I understand.  Thanks lenordiste!

RBS
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 39278901
you may want to look at display templates though... that for each looks suspicious in that it could be cleaner with a specific view :)
0
 

Author Comment

by:RBS
ID: 39278953
Thanks - next thing in my learning new stuff todo list after i get through present project..
RBS
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question