jquery - MVC - Data between ajax and controller -


i sending id value using ajax controller nothing appears on browser.

ajax part

$(function () {     $("#personeledit").click(function () {         $.ajax({             type: "post",             url: "/gorev/gorevpersonel/",             data: "{'id': '@{@model.id}'}",             contenttype: "application/json; charset=utf-8",             datatype: "json",             success: onsuccessyekiler,             failure: function (response) {                 alert(response.d);             }         });     }); }); function onsuccessyekiler(response) {     if (response.d != "false") {         eval(response.d);     } } 

controller part

[httppost]     public string gorevpersonel(string id)     {         if (id.equals(null)) { return ""; }         else          {             string retval = "";             string choval = "$('#s2_multi_value').val([{0}]).trigger('change');";             int gorevid = int32.parse(id);             int[] personeller = (from x in db.orgpersonelgorevler                                     x.gorevid == gorevid                                     select x.orgpersonel.id).toarray();              foreach (var item in personeller)             {                 retval += "'" + item + "',";             }             retval = string.format(choval, retval.substring(0, retval.length - 1));              if (string.isnullorempty(retval))                 retval = "false";             return retval;         }     } 

and retval equals $('#s2_multi_value').val(['6','7']).trigger('change');. controller returns retval nothing appears.

this part of want see result

 <select name="@html.namefor(x => x.gorevlendirilenpersoneller)" id="s2_multi_value" class="form-control" multiple>    <option value=""></option>    <optgroup label="personeller">    @html.action("_personellerigetir", "ortak");    </optgroup>  </select> 

additionally, tried input $('#s2_multi_value').val(['6','7']).trigger('change'); code using firebug , worked.

  1. you subscribe 'failure' event doesn't exist in jquery. try change 'error'.
  2. you using @{@model.id} in data parameter, doesn't return anything. try change @(model.id)
  3. here if (id.equals(null)) { return ""; } - if id null system.nullreferenceexception becaues trying call method on null reference. try use string.isnullorempty() instead.

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -