jquery - Looking for the right url in an Ajax json call -
i have next code in cshtml filling partial view result of selecting row in telerik grid control.
function onrowselected(e) { var tracksgrid = $('#tracks').data('tgrid'); articleid = e.row.cells[0].innerhtml; alert(articleid) var recordid = { id : articleid }; $.ajax( { type: 'html', contenttype: 'application/json; charset=utf-8', data: json.stringify(recordid), datatype: 'json', url: '@url.action("tracks", "home")', success: function (result) { alert('success'); }, error: function (error) { alert('fail'); } }); }
the alert shows id. far good.
but think url wrong , don't do. in home controller tracks expects string id.
public actionresult tracks(string id)
can me?
thanks
@3nigma nice! in error.responsetext see _tracks html. e.g. fieldset, legend, table , 10 data. in partialview: @model ienumerable fieldset, legend table @foreach (var item in model) , tr has item.description. else can do??
this partialview
@model ienumerable<web.models.tracks> <fieldset> <legend>tracks</legend> <table> <tr> <td> <div class="display-label"> unitno</div> </td> <td> <div class="display-label"> trackno</div> </td> <td> <div class="display-label"> description</div> </td> </tr> @foreach (var item in model) { <tr> <td> <div class="display-field"> item.unitno </div> </td> <td> <div class="display-field"> item.trackno </div> </td> <td> <div class="display-field"> item.description </div> </td> </tr> } </table> </fieldset>
$.ajax( { type: 'post', //or or put etc see docs more info contenttype: 'application/json; charset=utf-8', data:{id:articleid }, datatype: 'json', url: '@url.action("tracks", "home")', success: function (result) { alert('success'); }, error: function (error) { alert('fail'); } });
Comments
Post a Comment