0

Does anyone know why this isn't working, combination of 2 answers today. I'm just trying to get the parameter passed to show up in alert, everything else works so ignore the url action etc

$('#changetopicss').click(function () {
    $('#loadingAjaxs').show();
    $('#flubestext').hide();

    var link = '@Url.Action("Detail", "Topics", new { @id = 304,  @name = "newest", @forum = "all", @page = 0})';

    var dataid = $(this).data(id);
 //       link = link.replace("-1", $(this).data(id));
 //       link = link.replace("-2", $(this).data(shortname));
    window.alert(dataid);
        $('#contentwrap').load(link, function () {
            $('#loadingAjaxs').hide();
            $('#flubestext').show();
            window.history.pushState(null, 'title', '/topics');
        });
    });
</script>

<a id="changetopicss" data-id='@following.Id' data-shortname='@following.ShortName'>@following.Title</a>

everything else works, now trying to debug why i cant pass the data-id to window.alert as it wasn't working in url.action

1 Answer 1

2

Should be

var dataid = $(this).data('id');

A quoted string, not just an identifier.

Sign up to request clarification or add additional context in comments.

4 Comments

pointy do you know how these would be perceived by the controller (string or int etc?)
They don't exist in the context of the controller. They are executing in the browser javascript engine ....
they do once i reactivate the comented out lines and put -1 and -2 in the url.action link
@mxadam I don't know much about how asp.net works, so I can't say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.