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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:12:28+00:00 2026-05-27T20:12:28+00:00

Take for instance the following code for Edit action in my controller: // POST:

  • 0

Take for instance the following code for Edit action in my controller:

    // POST: /Admin/Text/Edit/5
    [HttpPost]
    [ValidateInput(false)]
    public virtual ActionResult Edit(TextViewModel editing)
    {
        if (!ModelState.IsValid)
            return View(editing);

        Text existing = _repository.Find(editing.Id);

        if (TryUpdateModel(existing)) {
            _repository.Update(existing);
            if(Request.IsAjaxRequest())
                return Content(bool.TrueString);
            else
                return RedirectToAction(pndng.Admin.Text.List());
        }
        else return View(editing);
    }

What I want this action to do is handle both classic (non AJAX form) and AJAX (jquery) POSTs. In case of AJAX POST it is very likely that the request is coming from an inline edit form. In this case, the action should just return the Content=Ok result. In case we have been editing the model in a form page and performed a classic postback we want to redirect the user back to the content List (see RedirectToAction()).

However, the thing bothering me is the if..else clause. I would like to abstract this away into an action filter/attribute. I would like to leave in the redirection call (as this is the default) but have the action filter to act upon it if it detects that the request was in fact AJAX request, meaning stop the redirection and just return the ContentResult or JsonResult.

Also feel free to respond if you think my workflow is wrong.

  • 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-27T20:12:28+00:00Added an answer on May 27, 2026 at 8:12 pm

    You should be to implement a custom ResultFilter to do what you want, by implementing IResultFilter. something like:

    public class AjaxOverrideFilter : IResultFilter
    {
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
    
        }
    
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (filterContext.HttpContext.Request.IsAjaxRequest() && filterContext.Result is RedirectResult)
                filterContext.Result = new ContentResult {Content = "Ok"};
        }
    }
    

    And then decorate that action with [AjaxOverrideFilter].

    This should override the result if its an ajax request and the result type was a redirect… At least, this should give you a push in the right direction. I’m not wildly convinced that this is a great architectural approach though…

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

Sidebar

Related Questions

Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string
I've been told that every COM method callable from C++ code (take for instance
For instance, take this piece of code: var person = new Person(); or for
Take this code: <?php if (isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; } if
I have the following code: public void Dispose() { if (_instance != null) {
The following code is part of a WCF service. Will eventWatcher take up a
I have a string with url.Please take a look at the following code.I am
For instance, if I was to create the following code: a_list = ['this', 'is',
Take the following code written in Java: choice = keyboard.nextByte(); switch (choice) { case
I am using following code to get List from xml file - public static

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.