MVC & Bootstrap Accordion


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)
                     <div id="collapseOne" class="accordion-body collapse ">
                         <div class="accordion-inner">
                             @Html.DisplayFor(modelItem => item.Answer)


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.

Who is Participating?
Roopesh ReddyConnect With a Mentor IT AnalystCommented:

You may have to use jQuery selectors to dynamically select!

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

Can you try like this -


Open in new window

Hope it helps u...
RBSAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.