Solved

MVC & Bootstrap Accordion

Posted on 2013-06-25
2
1,272 Views
Last Modified: 2013-06-27
Hi:

I'm trying to create a data-based FAQ in MVC4 using EntityFramework and Bootstrap.  

The following code works with 2 problems:

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

        </div>

Open in new window


The problems are:

1.  The same answer opens for all questions.  I am not sure how to dynamically refer to each question's answer;

2.  The answer comes from a sql server field of raw Html.  When I try to use Html.Raw instead of Html.DisplayFor, I get the error that "Cannot resolve the method 'Raw(lamda expression)

Any help in completing this greatly appreciated.

RBS
0
Comment
Question by:RBS
2 Comments
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
ID: 39282111
Hi,

You may have to use jQuery selectors to dynamically select!

Regarding Html.Raw(), do you have the model type as String?

http://msdn.microsoft.com/en-us/library/gg480740(v=vs.98).aspx

Can you try like this -

@Html.Raw(item.Answer)

Open in new window


Hope it helps u...
0
 

Author Closing Comment

by:RBS
ID: 39282187
thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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