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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:37:10+00:00 2026-06-14T13:37:10+00:00

I have a view that displays a list of user roles (e.g., administrator, operator,

  • 0

I have a view that displays a list of user roles (e.g., administrator, operator, etc) and an “Add” button that pops up a modal window, allowing the user to add a new role.

In my controller, I have this as my HttpPost method

    [HttpPost]
    public ActionResult Create(RoleModel model)
    {

        if (ModelState.IsValid)
        {
            var role = new RoleDto
                {
                    Name = model.Name,
                    Description = model.Description
                };

            var roleAdded = _rolePermissionsRepository.AddRole(role);
            if (roleAdded != null)
            {
                //CLOSE WINDOW
            }
            else
            {
                //PRINT ERROR MSG TO WINDOW
            }
        }
        return View();
    }

If the add to the DB is successful, I would like to close the modal window, and then refresh the list on my main index page.

If there’s some error while persisting to the DB, the modal window should remain open, and show some error.

How do I achieve that?

This is what I’m using on my Index page to pop up the window

    $("#open").click(function (e) {
        wnd.center();
        wnd.open();
    });
  • 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-14T13:37:11+00:00Added an answer on June 14, 2026 at 1:37 pm

    You should return a JsonResult to tell the browser what happened.

    [HttpPost]
    public ActionResult Create(RoleModel model)
    {
    
        if (ModelState.IsValid)
        {
            var role = new RoleDto
                {
                    Name = model.Name,
                    Description = model.Description
                };
    
            var roleAdded = _rolePermissionsRepository.AddRole(role);
            if (roleAdded != null)
            {
                //CLOSE WINDOW
                return Json(new { success = true });
            }
            else
            {
                return Json(new { error = "Error! Can't Save Data!" });
            }
        }
    
        return Json(new { error = "Generic Error Message!" });
    }
    

    Here is the javascript that should run in your wnd page, you show the error message if there is any, otherwise you close the window.

    $('form').submit(function(e) {
        e.preventDefault();
        $.post(this.action, $(this).serialize(), function(response) {
            if(response.error) {
                alert(response.error);
            }
            else {
                wnd.close();
            }
        }, 'json');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table view that displays a list that I want the user
I have a list view that displays a collection of items, each item has
I have created a list view that displays the names and dates of items
I have a jquery modal dialog that displays a partial view. The partial view
I have a view that displays a list of models. Some of the properties
Ok, currently I have a view in my android app that displays a list
I have a program that displays a list (a TableView). When the user clicks
I have a table view that displays a list of users. The avatar images
I have a Drupal view that displays vacation leaves for a particular employee. I
I have a WPF view that displays a Shipment entity. I have a textblock

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.