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 5941159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:04:15+00:00 2026-05-22T16:04:15+00:00

Currently I have a Controller, AssetController, that has methods for navigating a tree of

  • 0

Currently I have a Controller, AssetController, that has methods for navigating a tree of assets.

I use this controller to navigate a “gallery” of assets and the controller methods currently return ViewResult.

I am starting to build another way of viewing this same data which will make use of ajax and will not want ViewResult returned but rather JsonResult.

I would like to re-use as much of my controller logic as possible. I can think of two options here:

  1. Change all my controller methods to return only JsonResult then change my current View to use the json to display the full page.

    Drawbacks: This pushes more page loading / redirecting logic onto the client. It also make deep linking a problem I think. With full views the URL’s of pages are very “link friendly” in that a user can copy and paste a link and pass it to someone and it will go where they expect. Returning JsonResults mean the URL doesn’t change so deep linking becomes more challenging

  2. Refactor my current controller so that “shared” code is moved into private methods in the controller. Create new actions that return JsonResult and keep existing methods that return ViewResult.

    This is currently my choice as it seems to keep more code in the controller which makes unit testing it easier. But it also seems to be a little too coupled to the UI, what happens when I want to return the data in different formats, do I just keep adding new controller actions with different ActionResult types? Is that so bad?

Is there a smarter way to handle situation or is one of my approaches more favorable than the other?

UPDATE

Here is some code examples to clarify:

Currently I have this:

public ActionResult ViewObject(PathModel inPath)
{
    using (engine)
    {
      var metaData = engine.GetFileMetaData(inPath.Path);
  return View(metaData); //This is returning a ViewResult type
    }
}

I am thinking about doing something like this

private FileMetaDataModel ViewObjectInternal(PathModel inPath)
{               
  using (engine)
  {
      var metaData = engine.GetFileMetaData(inPath.Path);
      return metaData;
  }
}

public ActionResult ViewObjectAsJSON(PathModel inPath)
{
   var jsonResult = new JsonResult();
   jsonResult.Data = ViewObjectInternal(inPath).ToJson();

   return jsonResult // this is returning my data as JSON;
}

public ActionResult ViewObjectAsView(PathModel inPath)
{
  return View(engine.GetFileMetaData(inPath.Path)); //This is returning a ViewResult type
}
  • 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-22T16:04:16+00:00Added an answer on May 22, 2026 at 4:04 pm

    Why not just simply return ActionResult?

    public ActionResult Detail()
    {
        // controller logic here
    
        if (Request.IsAjaxRequest())
            return Json(model);
    
        return View(model);    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a abstract controller class that I all my controllers inherit from.
I am making use of Codeigniter and I currently have this URL format setup:
I currently have a controller method that returns a JsonResult: public JsonResult EditField(int FieldID,
I currently have a view controller that implements ASIHTTP for handling API calls. My
I have a controller action in my project that has a situation where it
I currently have a login link on my application that looks something like this:
I currently have this huge and slow code that takes forever to run.... Im
I currently have this: Hotels Controller class HotelsController extends AppController { var $name =
I am running JSF 2.0 I currently have one java controller that is called
I Have a controller that returns a viewModel. That viewModel has a property called

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.