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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With