Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1221
  • Last Modified:

MVC4 Html.Raw not working

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
RBS
Asked:
RBS
  • 3
  • 3
1 Solution
 
lenordisteCommented:
try this:
@Html.Raw(@item.Answer)

Open in new window

0
 
RBSAuthor Commented:
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
 
lenordisteCommented:
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
RBSAuthor Commented:
Excellent - Now I understand.  Thanks lenordiste!

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

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now