开发者

Looking for the right url in an Ajax json call

I have the next code in my cshtml for filling a partial view from the result of selecting a row in a 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',
         c开发者_JAVA百科ontentType: '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 an id. so far so good.

But I think the url is wrong and I don't what to do. In the home controller the Tracks expects an string id.

 public ActionResult Tracks(String id)

Can you help me?

Thanks

@3nigma Nice! In the error.responseText I see the _tracks as html. e.g. fieldset, legend, table and the 10 with data. In my partialView: @model IEnumerable a Fieldset, Legend table a @foreach (var item in Model) and tr has a item.Description. What else can I do??

this is my 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 GET or PUT etc see the DOCS for 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');
     }
 });

jquery ajax

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜