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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:47:35+00:00 2026-06-03T21:47:35+00:00

I am writing a single page ajax app with ASP.NET MVC – making heavy

  • 0

I am writing a single page ajax app with ASP.NET MVC – making heavy use of jQuery. I do something similar to the following throughout the app:

JS:

$.ajax({
    type: "GET",
    url: "/Home/GetSomePartialView/",
    data: someArguments,
    success: function (viewHTML) { 
        $("#someDiv").html(viewHTML); 
    },
    error: function (errorData) { onError(errorData); }
});

Controller C#:

public ActionResult GetSomePartialView(SomeArgumentModel someArguments)
{
    
    return PartialView("_CaseManager");
}

This works great. The viewHTML (in the ajax success function) is returned as a string and I can shove it on the page no problem.

Now what I would like to do is to return not only the PartialView HTML string, but also some sort of status indicator. This is a permissions thing – for instance, if someone tries to get to a portion of they app they don’t have permission to, I want to return a different PartialView than they asked for and also display a message in a popup window telling them why they got an View different from what they asked for.

So – to do this, I would like to do the following:

Controller C#:

public ActionResult GetSomePartialView(SomeArgumentModel someArguments)
{
    ReturnArgs r = new ReturnArgs();
    
    bool isAllowed = CheckPermissions(); 
    
    if (isAllowed) 
    {
        r.Status = 400; //good status ... proceed normally
        r.View = PartialView("_CaseManager");
    }
    else
    {
        r.Status = 300; //not good ... display permissions pop up
        r.View = PartialView("_DefaultView");
    }
    
    return Json(r);
}

public class ReturnArgs
{
    public ReturnArgs()
    {
    }

    public int Status { get; set; }
    public PartialViewResult View { get; set; }
}

JS:

$.ajax({
    type: "GET",
    url: "/Home/GetSomePartialView/",
    data: someArguments,
    success: function (jsReturnArgs) { 
        
        if (jsReturnArgs.Status === 300) { //300 is an arbitrary value I just made up right now
            showPopup("You do not have access to that.");
        }
    
        $("#someDiv").html(jsReturnArgs.View); //the HTML I returned from the controller
    },
    error: function (errorData) { onError(errorData); }
});

This SORTA works right now. I get a good object in JavaScript (what I am expecting to see), however I cannot see how to get at the full HTML string of the jsReturnArgs.View property.

I am really just looking for the same string that would be returned if I were just returning the PartialView by itself.

(As I mentioned at the beginning, this is a single page app – so I can’t just redirect them to another View).

  • 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-03T21:47:37+00:00Added an answer on June 3, 2026 at 9:47 pm

    So – using the following posts I got this working:

    Partial Views vs. Json (or both)

    Render a view as a string

    They both lay it out nicely, then I changed my code to the following:

    C#:

    public ActionResult GetSomePartialView(SomeArgumentModel someArguments)
    {
        ReturnArgs r = new ReturnArgs();
    
        bool isAllowed = CheckPermissions(); 
    
        if (isAllowed) 
        {
            r.Status = 400; //good status ... proceed normally
            r.ViewString = this.RenderViewToString("_CaseManager");
        }
        else
        {
            r.Status = 300; //not good ... display permissions pop up
            r.ViewString = this.RenderViewToString("_DefaultView");
        }
    
        return Json(r);
    }
    
    public class ReturnArgs
    {
        public ReturnArgs()
        {
        }
    
        public int Status { get; set; }
        public string ViewString { get; set; }
    }
    

    JS:

    $.ajax({
        type: "GET",
        url: "/Home/GetSomePartialView/",
        data: someArguments,
        success: function (jsReturnArgs) { 
    
            if (jsReturnArgs.Status === 300) { //300 is an arbitrary value I just made up right now
                showPopup("You do not have access to that.");
            }
    
            $("#someDiv").html(jsReturnArgs.ViewString); //the HTML I returned from the controller
        },
        error: function (errorData) { onError(errorData); }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are writing single page app (SPA) in which users connect to different database
I'm writing a little single page app (using knockout.js :-)) whereby i have a
I'm writing an asp.net Web Application. I wrote a login page that authenticates a
I'm writing single-page web application. Client interacts with server using AJAX retrieving quite complex
So I'm writing a disposable script for my own personal single use and I
I am writing an ASP.NET website, which is a new framework for me. I
I'm writing jQuery for a page that is a complex mess of many DOM
I'm diving into writing a mobile app with jQuery Mobile/PhoneGap. I'm using this sample
I'm writing a page with examples that demonstrate the use of my js library.
I am writing a single page javascript application using the HTML5 History API. The

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.