Search code examples
asp.net-mvc-4google-plus-one

how to add google 1 button using asp MVC 4 and add in internet application


how to add google +1 button using asp MVC 4 and add in internet application


Solution

  • First of all: https://developers.google.com/+/plugins/+1button/

    Adding a Google +1 button doesn't have much to do with MVC 4 per se, but a potential implementation looks something like this:

    In View/Partial View

    <footer>
        <ul>
            <li>
                <div class="g-plusone" data-annotation="none"></div>
            </li>
    
            @* other buttons/links/whatever *@
    
        </ul>
    </footer>
    

    In _Layout.cshtml corresponding to the View

    <script>
        (function() {
            var po = document.createElement( 'script' ); po.type = 'text/javascript'; po.async = true;
            po.src = 'https://apis.google.com/js/plusone.js';
            var s = document.getElementsByTagName( 'script' )[0]; s.parentNode.insertBefore( po, s );
        } )();
    </script>
    

    Note that you might load this script conditionally, place it within a @section, etc.