asp.net mvc - javascript parameter doesnt exist in the current context - Stack Overflow

why doesnt this work? how can i declare these? considering topicid will be an int and topicname will be

why doesnt this work? how can i declare these? considering topicid will be an int and topicname will be a string.

function changetotopicdetail(topicid, topicname) {
    $('#loadingAjaxs').show();
    $('#flubestext').hide();
    $('#contentwrap').load('@Url.Action("Detail", "Topics", new { @id = topicid,  @namespace = topicname, @Forum = "all", @page = 0})', function () { 
    $('#loadingAjaxs').hide();
   $('#flubestext').show(); 
   window.history.pushState(null, 'title', '/topics');
   })
}

thanks

why doesnt this work? how can i declare these? considering topicid will be an int and topicname will be a string.

function changetotopicdetail(topicid, topicname) {
    $('#loadingAjaxs').show();
    $('#flubestext').hide();
    $('#contentwrap').load('@Url.Action("Detail", "Topics", new { @id = topicid,  @namespace = topicname, @Forum = "all", @page = 0})', function () { 
    $('#loadingAjaxs').hide();
   $('#flubestext').show(); 
   window.history.pushState(null, 'title', '/topics');
   })
}

thanks

Share Improve this question edited Sep 28, 2013 at 16:21 Imran 5047 silver badges15 bronze badges asked Sep 28, 2013 at 13:32 mxadammxadam 1672 silver badges14 bronze badges 3
  • see answer here: stackoverflow./questions/9751109/… – alxndr Commented Sep 28, 2013 at 13:36
  • i dont see how that has any relevence to my question? – mxadam Commented Sep 28, 2013 at 13:42
  • @alxndr posted a question that is totally relative to yours... is the same mistake you're doing on this. – DontVoteMeDown Commented Sep 28, 2013 at 13:48
Add a ment  | 

1 Answer 1

Reset to default 8

According to @alxndr tip, this question has the same mistake and it is solved with a code like that:

function changetotopicdetail(topicid, topicname) {
    $('#loadingAjaxs').show(); 
    $('#flubestext').hide();

    var link = '@Url.Action("Detail", "Topics", new { @id = -1,  @namespace = -2, @Forum = "all", @page = 0})';

    link = link.replace("-1", topicid);
    link = link.replace("-2", topicname);

    $('#contentwrap').load(link, function () { 
        $('#loadingAjaxs').hide();
        $('#flubestext').show(); 
        window.history.pushState(null, 'title', '/topics'); 
    });
}

You mistake is that you're trying to access two JavaScript variables(topicid and topicname) in the Razor - view - context. Razor can't access it, so those two variables are unknown for it. What the code is doing is to print the @Url.Action result on a JavaScript variable and then, in JavaScript (where you can access those parameters) replace that link joker chars -1 and -2 with the parameters. So you got the link the way you need it. Hope my explanation is clear.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745233783a4617792.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信