Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:14:22+00:00 2026-05-22T22:14:22+00:00

I am trying to build a sample for myself using MVC3, Razor view engine

  • 0

I am trying to build a sample for myself using MVC3, Razor view engine and JQuery UI.

From the controller I return a ViewModel (which has List) and able to wrap the JQuery Accordion around the html segments. Everything works as expected.

Now, I am trying to make it little better.
1) Would like to have a pagination bar, which can refresh the Accordion depending upon the page selected and number of items per page selected (I know what needs to be done in controller etc. My javascript skills are not so good when compared to c# 🙁 )

2) I would like to be able to select the “display type” for the data. For ex, if you see Slickdeals website, we can choose, Grid or Accordion or simple list. It appears it just applies a template over the data and refreshes the html.

I am wondering how best this can be achieved. (one thought that came to my mind is, send an AJAX request to controller with the desired display type and controller can render the view and return the string as response which can then be applied as html for the element. Is there a better way, I mean data is already in the browser so can we just apply some template and just re-render the same data?)

For both (1) and (2), I would like to avoid full page post back.

(I will try to add more details)

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:14:22+00:00Added an answer on May 22, 2026 at 10:14 pm

    Re (2): I think it’s a bad idea to generate the HTML inside the controller — separation of concerns suggests that the View should be solely responsible for the HTML.

    However, you can have a property in your View Model that tells the view which version to generate: e.g.

    public class XyzModel
    {
        public string displayType { get; set; }
        // ... other properties
    }
    

    Then in the View, you can test this variable:

    @if (Model.displayType == "grid")
    {
       // html for grid
    }
    else if (Model.displayType == "accordian")
    {
       // html for accordian
    }
    

    etc., all html blocks using the same data.

    If you want to use Ajax to populate this, you can isolate this code inside a partial view, and populate it using jQuery, something like:

    $.post(
        form.attr("action"),
        form.serialize(),
        function (data) {
              $("#dataDisplay").html(data);
        });
    

    where the dataDisplay section might be like:

    <div id="dataDisplay">
    @Html.Partial("DataDisplayPartial", Model)
    </div>
    

    and the DataDisplayPartial view would contain the above code … something like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a sample which send a very short sentence (less
I am trying to build sample JSF 2 based autocomplete form. I am using
I'm trying to build a sample test class using junit framework. I've downloaded junit4.9b3.
I'm currently trying to build a simple component which should monitor, if the user
I'm trying to build a very, very simple micro-webapp which I suspect will be
I'm trying to build a jQuery plugin that filters the provided jQuery object to
I'm trying to build a simple unit test executable, using cpputest. I've built the
I'm trying to build a C++ extension for python using swig. I've followed the
I'm trying to build this iPhone sample: http://trac.pjsip.org/repos/wiki/Getting-Started/iPhone but I'm having trouble since I
I am trying to build a grid, using class info and its properties along

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.