Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MVC4 Html.Raw not working

Posted on 2013-06-26
6
Medium Priority
?
1,192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 11

Accepted Solution

by:
lenordiste earned 2000 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
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 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