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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:19:02+00:00 2026-06-10T10:19:02+00:00

I currently have a MVC 3 Web Application with around 50 Views. Is it

  • 0

I currently have a MVC 3 Web Application with around 50 Views.

Is it somehow possible to provide some kind of API next to my Views so everything still works fine and dandy?

My kinda perfect world idea:

Server is running and every request gets to its view. The user can decide in his get request if he wants the raw data in lets say JSON. Additional to the raw data also the Structure/Names of the Viewmodel will be parsed so the Modelbinder can do his stuff.

or another approach might be to somehow deactivate my Views to have only the API available (again with raw data and structure).

Is this even possible (the modelbinder is kinda a big concern) and maybe even without much effort/trouble to do?

  • 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-10T10:19:04+00:00Added an answer on June 10, 2026 at 10:19 am

    If you don’t want to do everything all over again with WebAPI, you can implement some ActionFilterAttribute to change the ActionResult based on some querystring f.i.
    Something like this:

    public class ResultSwitcherAttribute: ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.HttpContext.Request["data"] != null && filterContext.HttpContext.Request["data"] == "json")
            {
                filterContext.Result = new JsonResult
                    {
                        Data = (filterContext.Result as ViewResult).Model,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
            }
        }
    }
    

    Then, you’ll register that either in application_start or per controller/action like this:

    [ResultSwitcherAttribute]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
    
            return View(new TestModel()
                {
                    Web = "http://www.mywebpage.com", Name = "Yngve"
                });
        }
    }
    

    When you now access your url with ?data=json you’ll get a JSON-representation of the Model, instead of the view.

    EDIT: Code sample updated

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

Sidebar

Related Questions

I have a Clustered Windows Hosting site which currently hosts an MVC Web Application
I currently have a web application written by ASP.NET MVC. Now I want to
currently I have a custom VirtualPathProvider in a Asp.net MVC web application. This VirtualPathProvider
I currently have a ASP.Net MVC web application that needs to upload large files
Currently I'm trying to port a web application(ASP.NET MVC) to windows azure and have
We currently have a classic ASP.NET web application which serves as our API. It
I have a MVC 4 project I am currently working on and need some
I'm developing an MVC application and I have a routine that gets the currently
First some background, I am currently working on a relatively large Asp.Net MVC application
So I have a spring mvc web application that I built in IntelliJ 9,

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.