ASP.NET MVC - JSON响应向我发送一个文件而不是执行该函数来关闭jqueryUI对话框 [英] ASP.NET MVC - JSON response sends me a file instead of executing the function to close the jqueryUI dialog

查看:69
本文介绍了ASP.NET MVC - JSON响应向我发送一个文件而不是执行该函数来关闭jqueryUI对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在返回一个json数据,我可以确认它正在将数据带回客户端。但它不是更新我的jqueryaccordion,而是要求我保存或打开文件。下面是我的脚本和控制器。我已经使用jquery模式对话框通过部分视图编辑员工详细信息,点击更新按钮应该更新手风琴列表中的相应员工。非常感谢任何帮助 - 谢谢



通过IE工具进行调试时,我注意到当点击更新按钮时,请求标签中的发起人显示点击。我猜这应该是''XMLHttpRequest''而是。希望这些信息有所帮助谢谢





**主视图**



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" })





**使用编辑员工表格的部分视图 - EditEmployee.cshtml * *







**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>
         <div class="editor-field">
             @Html.TextAreaFor(model => model.Name)
             @Html.ValidationMessageFor(model => model.Name)
         </div>

 }





**行动结果返回包含editemployee表单的部分视图**







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


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





**更新员工详细信息后返回Json Result的控制器**





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

[HttpPost]
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 () {
               $(".editLink").button();

           $('#updateDialog').dialog({
               autoOpen: false,
               width: 400,
               resizable: false,
               modal: true,
               buttons: {
                   "Update": function () {
                       $("#update-message").html('');
                       $("#updateEmployeeForm").submit();
                   },
                   "Cancel": function () {
                       $(this).dialog("close");
                   }
               }
           });

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

                   var $form = $("#updateEmployeeForm");
                   // Unbind existing validation
                   $form.unbind();
                              dialogDiv.dialog('open');
               });
               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
 $('#updateDialog').dialog('close');
 $('#commonMessage').html("Update Complete");
 $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
 alert("hello");

       }

推荐答案

function (){


。editLink ).button();
(".editLink").button();


' #updateDialog' ).dialog({
autoOpen: false
width: 400
可调整大小: false
modal: true
buttons:{
更新 function (){
('#updateDialog').dialog({ autoOpen: false, width: 400, resizable: false, modal: true, buttons: { "Update": function () {


这篇关于ASP.NET MVC - JSON响应向我发送一个文件而不是执行该函数来关闭jqueryUI对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆