Click here to Skip to main content
13,054,615 members (62,290 online)
Rate this:
Please Sign up or sign in to vote.
I'm returning a json data, and I can confirm that it is bringing data back to client. but instead of updating my jqueryaccordion, it asks me to save or open the file. Below is my script and controller. I have used jquery modal dialog to edit the employee details through a partial view, and clicking on update button should update the respective employee in the accordion list.Any help would be greatly appreciated - thanks

When debugging through IE tools, I noticed that when the 'update' button is clicked, the 'initiator' in the 'request' tab shows 'click'. I am guessing this should be 'XMLHttpRequest' Instead. Hope this information helps. Thanks

**Main View**

@Html.ActionLink("Edit Employee", "EditEmployee", "Home",
                        new { id = item.Id }
                        , new { @class = "editLink" })

**Partial View with Edit Employee Form - EditEmployee.cshtml**

@using (Ajax.BeginForm("EditEmployees", "Home", new AjaxOptions
             InsertionMode = InsertionMode.Replace,
             HttpMethod = "POST",
             OnSuccess = "updateSuccess"
         }, new { @id = "updateEmployeeForm" }))
         <div class="editor-label">
             @Html.LabelFor(model => model.Name)
         <div class="editor-field">
             @Html.TextAreaFor(model => model.Name)
             @Html.ValidationMessageFor(model => model.Name)


**Action Result that returns partial view containing the editemployee form**

Public ActionResult EditEmployee(int id)
   //DataAccess part
   return PartialView("EditEmployee",employeedata);

**Controller that returns Json Result after updating the employee details**

    Public JsonResult EditEmployee(Models.Employee employee)  
           //Data access part
         JsonResult result = new JsonResult();
                                result.Data = employeeData;
                                return result;

**Script on Main View**

  <script type="text/javascript">
           var linkObj;
           $(function () {

               autoOpen: false,
               width: 400,
               resizable: false,
               modal: true,
               buttons: {
                   "Update": function () {
                   "Cancel": function () {

           $(".editLink").click(function () {
               //change the title of the dialog
               linkObj = $(this);
               var dialogDiv = $('#updateDialog');
               var viewUrl = linkObj.attr('href');
               $.get(viewUrl, function (data) {

                   var $form = $("#updateEmployeeForm");
                   // Unbind existing validation
               return false;


function updateSuccess(data) {
// I want to make sure that this function gets executed on Success instead of a file being sent back to me from the server
 $('#commonMessage').html("Update Complete");

Posted 11-Apr-13 4:52am
Updated 12-Apr-13 0:38am
Moykn 11-Apr-13 13:59pm
is this right? @using (Ajax.BeginForm("EditEmployees", "Home", new AjaxOptions shouldn't be @using (Ajax.BeginForm("EditEmployee", "Home", new AjaxOptions ?
devdev13 12-Apr-13 6:37am
Yeah. That's right. It is spelt correctly in the code. Thanks. Any other suggestions ?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


This normally occures if you try to post a form in an IFrame and the result is JSON (mostly used in Ajax-fileuploads.

The problem is (in the above mentioned scenario) that IE does not detect the JSON result as a text to display, so it assumes that you want to download it.

To circumvent this behaviour, you can simply change this:

JsonResult result = new JsonResult();
result.Data = employeeData;
return result;

into this:

JsonResult result = new JsonResult();
result.Data = employeeData;
result.ContentType = "text/plain";
return result;

After this change, IE will assume that he will get Text, so it displays it correctly.

Give it a try, perhaps this also solves your problem :)
Hope this helps.

Best regards and happy coding,
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Probably you have forgotten to add jquery.unobtrusive-ajax.min.js to your page, check it please.

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100