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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:16:07+00:00 2026-05-30T06:16:07+00:00

when I create a area I use JQuery to call the action create the

  • 0

when I create a area I use JQuery to call the action create the action save to the db and return jsaon now when is save i want to be rendered to my index view how can i do that?? whith my code i have is that posible?
i tried to call to the action index with jquery it call fine to the action but not render to the view index

 [HttpPost]
        public ActionResult Create(int? id,string nombre, int idDpto )
        {
            try
            {
                if (id != null)
                {

                    Area c = (from x in db.Areas
                              where x.AreaId == id
                                      select x).First();
                    c.NombreArea = nombre;
                    c.DepartamentoId = idDpto;
                    db.SaveChanges();

                    return Json(new { ok = true, message = "saved employee " });
                }

                    Area e = new Area()
                    {
                          NombreArea = nombre,
                          DepartamentoId = idDpto
                    };
                    db.Areas.Add(e);
                    db.SaveChanges();
                    return Json(new { ok = true, message = "saved employee " });//+ emp.NameEmployee
            }
            catch (Exception ex)
            {

                return Json(new { ok = false, message = ex.Message });
            }
        }


function saveEmployee() {

        var urlSave = '@Url.Action("Create")';
        var iddpt = $("#cmbDept").val();
        var name = $("#txtemp").val();
        var idArea = $("#AreaId").val();
        if (!name) {
            window.alert('el nombre y el departamento son requeridos');
        }
        else {

            if (! iddpt) {
                window.alert('el departamento es requerido');    
            }
            else {
                $.ajax({
                    type: "POST",
                    url: urlSave,
                    data: { id: idArea, nombre: name, idDpto: iddpt },
                    success: function (returndata) {
                        if (returndata.ok) {
                            window.alert(' Guardado ');
                        }
                        else {
                            window.alert(' error : ' + returndata.message);
                        }

                    }
                }
                    );
            }
        }
    }
  • 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-30T06:16:08+00:00Added an answer on May 30, 2026 at 6:16 am

    The fundamental issue here is the difference between an AJAX call from within JavaScript and a regular web request. From the server’s perspective, there isn’t much of a difference. It’s just how the browser handles those.

    Your Create action is set up to be used by an AJAX call, which you’re doing. That’s all well and good. But I assume that Index is not. That one expects to be a regular request. As I said, from the server’s perspective, there really isn’t a difference. So, as you’ve observed, the call to Index happens just fine. It just doesn’t “render” in the browser.

    The terminology is a little mixed up here. You don’t want to “render the view with jQuery,” you want to direct the browser to make that request. When should this happen? I’m assuming that you want this redirect to take place perhaps after the success in your AJAX call?

    If you want your JavaScript to redirect, then you’re on the right track. Just approach it differently. jQuery doesn’t call the Index view in an AJAX manner (because it wouldn’t know what to do with the response). Simply use a JavaScript call to redirect the user to another resource:

    window.location.href = "http://yourserver/controller/action/etc";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can create the following and reference it using area[0].states[0] area[0].cities[0] var area =
I want to create a headline (h2) with an image at the right-most area
I want to create basic line, bar, pie and area charts for .NET 3.5
I'm trying to use jQuery to dynamically create an image map, and I ran
I want to create a drop down area like once in the top of
I try to create an area onto a CDialog, where I can put some
I'm trying to catch a double-click event in a TreeView's empty area to create
I need to create a cherrypy main page that has a login area. I
I am trying to create a gradient fill for a series in an area
If i create a program, which in one small out of the way area,

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.