开发者

ASP.NET MVC 3: Get partial views inside a view folder

I want to create a FAQ page, which gets the FAQs from partial views located inside a defined view folder. Each partial view would contain the question, the answer and some sort order field.

I can't find anything which gives me the complete list of views inside a view folder.

Update for clarification: A FAQ would look something like this:

    @model Busker.MVC.Models.FAQ.FAQModel
    @{
        var title = "What is xxxxx?";    
    }
    <p>
      Please register @Html.ActionLink("Register", "register", "Member") here.
    </p>

The index page of the FAQ should iterate through all FAQs and first display the questions with and anchored links and then display all titles and questions开发者_StackOverflow中文版 in blocks.

Another approach I'm looking into, is loading the views in ViewAllFaqsModel. Havent' figured out how to get the partial view into a collection of the model though..


Your approach of using partial views is wrong. A partial view is created to be reused and not to be a file which actually contains content.

What I would do: Create a file (XML) or database which contains questions, answers and order fields, create a model for it and ouput in on your faq site.

So you could do something like this in your aspx file:

<% foreach(FAQEntry faqentry in faqentries)
{ %>
    <h2><%= faqentry.Question %><2/>
    <!-- And so on... -->
<% } %>


I think you only need one partial view that you render many times passing each time a ViewModel with the fields that you mentioned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜