locked
Is it possible to dynamically update the Razor Twitter Web helper? RRS feed

  • Question

  • User-1484187403 posted

    I realize that jQuery has no carnal knowledge of Razor, so I can't reference a Razor var etc. from jQuery, so how *can* I update a Razor val in, e.g., a button's click event?

    In the start of a page, I load a tab with Tweets like so:

                    <div id="duckbilledPlatypusTab-Twitter">
                        @*giving them a width of 40% simply added margins, effectively*@
                        <span id="spanProfile" style="display: inline-block; vertical-align: top">@Twitter.Profile("WebMatrix", numberOfTweets: 42, scrollBar: true, avatars: true)</span>
                        <span id="spanSearch" style="display: inline-block; vertical-align: top">@Twitter.Search("WebMatrix", scrollBar: true, avatars: true)</span>
                    </div>

    ...but when a button is mashed, I want to update that tab's contents by changing the spans' contents to:

    @Twitter.Profile(<value entered by user>);
    -and: 
    @Twitter.Search(<value entered by user>); 

    How can this be done? Can a click event be handled in Razor code? If so, how is this accomplished exactly?

    Sunday, May 19, 2013 11:17 AM

Answers

  • User-1333008299 posted

    Hello Shannon,

    It's possible to execute razor code from a click event. You can achieve it by creating a javascript function:

    function checkboxEvent(cb, id) {
             $.get(
                "/extract/saveEst.cshtml",
                { "chckBox": cb.checked, "id": id },
                function(data) {
                }
            );
         }

    The checkboxEvent function evoques a razor page where your code will reside.

     

    HTH,

    Jose.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 23, 2013 6:36 AM