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

  • SEARCH
  • Home
  • 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 8515707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:13:20+00:00 2026-06-11T05:13:20+00:00

So the problem is the following: I have an action method that returns json.

  • 0

So the problem is the following: I have an action method that returns json. What I need to do is use that json to construct some html based on it. For example lets say I receive a list of cars. What I want to do is display the list like this for example:

<div id="cars">
@foreach(var car in Model)
{
  <p>car.Name</p>
}
</div>

<div id="pageLinks">
  @Html.MyPageLinks(Model.PageInfo)
</div>

Currently this is a view and what I do is render that view in the controller and return the whole result as json result (check this link). Everything works great, however there is one major drawback – the action method is not testable, as I have to mock tons of things in order to make the FindPartialView to work (and currently I am stuck with this). Even worse, I have coupled the view with the action, i.e. changes to the view will also harm the unit tests and this is not acceptable.

On the other hand using javascript to generate all that html seems a very bad approach, since it is going to be a lot of raw javascript and jquery (keep in mind that even in my simplified example there will be a lot of js and I will loose the option to test MyPageLinks since everything will be js).

What I need/want to do is return only json (just the data objects, no html) and in the view to have something like a template that will be applied once the json is returned.

  • 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-06-11T05:13:22+00:00Added an answer on June 11, 2026 at 5:13 am

    Simply return HTML, not JSON from your controller action. So put the view snippet you have shown into a partial wrapped inside a div:

    <div id="paginatedCars">
        @Html.Partial("Cars")
    </div>
    

    and then have the controller action that you are invoking return this updated partial.

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

Sidebar

Related Questions

I have an Action Method that returns a JSON-serialized object. The problem I'm having
Hi i have following Problem. I write a Mediawiki Extension where i need some
I have the problem that my code isn't triggering the action in my backing
I have a problem with authorized SSL connection. I have created Struts Action that
I have a controller action that effectively simply returns a JsonResult of my model.
I have some kind of controller: @Controller public class DefaultController { @RequestMapping(value=/index.html, method=RequestMethod.GET) public
I have the following HtmlHelper method that I want to create a button that
I have ASP.NET MVC3 project and I am writing some extension methods that returns
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem: I have built a tabbar application with 4 tabs. I

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.