?
Solved

MVC & Bootstrap Accordion

Posted on 2013-06-25
2
Medium Priority
?
1,419 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
[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
2 Comments
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 2000 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

752 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