jquery - ASP.NET MVC - JSON response sends me a file instead of updating the jqueryUI -


i'm returning json data, , can confirm bringing data client. instead of updating jqueryaccordion, asks me save or open file. below script , controller. have used jquery modal dialog edit employee details through partial view, , clicking on update button should update respective employee in accordion list.any appreciated - thanks

update

when debugging through ie tools, noticed when 'update' button clicked, 'initiator' in 'request' tab shows 'click'. guessing should 'xmlhttprequest' instead. hope information helps. thanks

main view

@html.actionlink("edit employee", "editemployees", "home",                         new { id = item.id }                         , new { @class = "editlink" }) 

partial view 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>     </fieldset> } 

action result returns partial view containing editemployee form

public actionresult editemployee(int id) { //dataaccess part return partialview("editemployee",employeedata); } 

controller returns json result after updating 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 title of 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) {  // want make sure function gets executed on success instead of file being sent me server   $('#updatedialog').dialog('close');   $('#commonmessage').html("update complete");   $('#commonmessage').delay(400).slidedown(400).delay(3000).slideup(400);   alert("hello");          } 

$.get(viewurl, function (data) { 

if how ajax data, can say, server code return error:

jsonresult result = new jsonresult();     result.data = employeedata;     return result; 

because default jsonresult allow post requests

as solution can use jsonrequestbehavior.allowget


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -