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
1 Answer
Reset to default 8According 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条)