asp.net mvc - Passing a URL through jQuery with awkward routing -


i familiar how pass data through url through jquery, asp.net mvc controllers, writing code today , came upon interesting url cannot quite figure out how format...

the route reads ...

/////////////////////////////////////////// // route: /member/{0}/characters /////////////////////////////////////////// public actionresult characters(int member){  // list of member's characters } 

so url have 'parameter' right in middle. curious me, because i'm not sure how translates jquery "data" property on $.ajax. set ....

$.ajax({     url: '/member/characters',     datatype: 'json',     data: { member: 1 } }).done(function (data) { viewmodel.set("player", data); }); 

but can't seem work in situation. suppose hokey string formatting, hoping bit more cleanly...

does have suggestions handling odd routes this?

you won't able use data parameter since sets query string attributes. value part of path, you'll need different. try using @url.action generate correct url, , omit data parameter.

$.ajax({     url: '@url.action("characters", "member", new { member = 1 })', }).done(function (data) { viewmodel.set("player", data); }); 

this not work if member id dynamically chosen javascript.

to that, you'll have manually create url:

var url = '/member/' + memberid + '/characters'; 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -