Solved

MVC4 Html.Raw not working

Posted on 2013-06-26
6
989 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
Comment Utility
try this:
@Html.Raw(@item.Answer)

Open in new window

0
 

Author Closing Comment

by:RBS
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:RBS
Comment Utility
Excellent - Now I understand.  Thanks lenordiste!

RBS
0
 
LVL 11

Expert Comment

by:lenordiste
Comment Utility
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
Comment Utility
Thanks - next thing in my learning new stuff todo list after i get through present project..
RBS
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now