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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:58:26+00:00 2026-06-11T22:58:26+00:00

I have one asp.net mvc 3 application. public ActionResult Students() { return View(); }

  • 0

I have one asp.net mvc 3 application.

public ActionResult Students()
{ 
  return View();
}

When i request these actions thru browser, everything works fine. It returns appropriate views, but when such actions are called from another site(across domain) thru jQuery Ajax call, It give transport error.

as a result we need to return such views in JsonpResult type, but now the problem is how do browser load such views of type JsonpResult ? it doesn’t return html part of the view instead it asks browser to save view result of type Jsonp.

Any suggestion, how to solve this ?

thanks.

  • 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-11T22:58:28+00:00Added an answer on June 11, 2026 at 10:58 pm

    You could use the RenderPartialViewToString method shown in this answer to render the view to a string and then return the custom JsonpResult you have written:

    public class StudentsController : Controller
    {
        public ActionResult Index()
        {
            MyViewModel model = ...
            return new JsonpResult(new 
            {
                html = RenderViewToString("Index", model)
            });
        }
    
        public string RenderViewToString(string viewName, object model)
        {
            ViewData.Model = model;
            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString();
            }
        }
    
        protected string RenderPartialViewToString(string viewName, object model)
        {
            if (string.IsNullOrEmpty(viewName))
            {
                viewName = ControllerContext.RouteData.GetRequiredString("action");
            }
    
            ViewData.Model = model;
            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);
                return sw.GetStringBuilder().ToString();
            }
        }
    }
    

    The JsonpResult class used here could be found in this post.

    And now you could invoke this controller action using AJAX from another domain:

    var url = 'http://example.com/students/index';
    $.getJSON(url + '?callback=?', function (data) {
        alert(data.html);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one View and one Controller in my ASP.net MVC Application. I have
I am working with an ASP.NET MVC application. I have one master page having
I have one question; In my ASP.NET MVC web application have to do certain
I have an ASP.NET MVC application that has one part where I dont really
I am working in an ASP.NET MVC Application. I have a view model as
In a Rob Conery-style ASP.NET MVC application, you typically have a repository: public class
I have an asp.net MVC application that has one section /admin locked down via
I have two ASP.NET MVC web applications. One of them logs unhandled exceptions to
i need to have one project on asp.net mvc 1 but i want to
I have got one weird issue. I am working on an asp .net mvc

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.