Solved

MVC & Bootstrap Accordion

Posted on 2013-06-25
2
1,291 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get id from json Data with NewtonSoft 3 35
Name space syntax error 12 44
How to write an English digest paper 6 25
Set value of dynamically created checkboxlist 2 12
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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

863 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

22 Experts available now in Live!

Get 1:1 Help Now