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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:18:57+00:00 2026-06-04T04:18:57+00:00

When I press the Save button I return from my Controller this: return Json(new

  • 0

When I press the Save button I return from my Controller this:

return Json(new { success = true });

and my whole browser viewport is white and in the left top corner I see my json data I have returned:

{"success":true}

Question: What do I have to change that this white viewport is fixed?

My expectation is to check for success: true/false at client side and depending on the value I close the dialog or change some data and the site who called the dialog should remain.

   $(document).ready(function () {

        // the div holds the html content
        var $dialog = $('<div></div>')  
        .dialog({
            autoOpen: false,
            title: 'This is the dialogs title',
            height: 400,
            width: 400,
            modal: true,
            resizable: false,
            hide: "fade",
            show: "fade",
            open: function (event, ui) {
                $(this).load('@Url.Action("Create")');
            },
            buttons: {
                "Save": function () {
                    var form = $('form', this);
                    $(form).submit();
                },
                "Close": function () {
                    $(this).dialog("close");                   
                }
            } // no comma
        });

        $('#CreateTemplate').click(function () {
            $dialog.dialog('open');
            // prevent the default action, e.g., following a link
            return false;
        });

    });

</script>

Create view:

@using (Html.BeginForm("JsonCreate", "Template"))
{ 
    <p class="editor-label">@Html.LabelFor(model => model.Name)</p>
    <p class="editor-field">@Html.EditorFor(model => model.Name)</p>
    <p class="editor-field">@Html.ValidationMessageFor(model => model.Name)</p>    
}

UPDATE

"Save": function () {
                    var form = $('form', this);
                    debugger;
                    $.ajax({
                        url: this.action,
                        type: 'POST',
                        data: form.serialize(),
                        dataType: 'json',
                        success: function (result) {
                            debugger;   
                            if (result.success) {
                                $(this).dialog("close");
                                // Update UI
                            }
                            else {
                                // Reload the dialog to show model errors                    
                                $(dialog).html(result);
                            } // else end
                        } // success end
                    }); // ajax post end

                },

Controller POST action:

  [HttpPost]
        public ActionResult JsonCreate(Template template)
        {
            if (ModelState.IsValid)
            {
                _templateDataProvider.AddTemplate(template);
                return Json(new { success = true });
            }

            return Json(new { errors = GetErrorsFromModelState() });
        }
  • 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-04T04:18:58+00:00Added an answer on June 4, 2026 at 4:18 am

    You have to do Ajax submit, so that the page stays on the same url:

                "Save": function () {
                    var form = $('form', this);
                    //$(form).submit();
                    $.post(form.prop('action'), form.serialize(), function(response){
                        //do something with response data or ignore it
                    }, 'json');
                },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT works, Edit button works, but after editing, when I press Save the Grid
I have the following code. When I press my save button, three requiredfieldvalidators run
If I open a doc in read only mode I'm able to press save
When I press F5 the project compiles, and the new web page launches. However,
when we press on the Home button two times then we see the all
I spend the whole morning today searching for a way to save an array
I have view a that has a table cell and a save button. If
I'm trying to get webrat to select a radio button from a list, using
I wrote the App that count something by press on + button and show
If you press Shift+Ctrl+T or choose Navigate > Open Type... you get the Open

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.