如何将.cshtml转换为.aspx

时间:2018-12-26 16:16:20

标签: asp.net razor

当.cshtml上的相同代码更改为.aspx时,无法在Visual Studio中运行时,我遇到了一个问题。我应该如何更改任何格式或在.aspx上运行的编码?这是一个聊天室编码

@section scripts
{
    <script src="~/Scripts/jquery.signalR-2.4.0.min.js"></script>
    <script type="text/javascript" src="~/signalr/hubs"></script>
    <script type="text/javascript">
        $(function () {
            var $chats = $('#chats'),
                chatHub = $.connection.chatHub;

            chatHub.client.gotMessage = function (nickname, message) {
                $chats.append('<li><span class="label label-primary">' + htmlEncode(nickname)+'</span>' + htmlEncode(message));
                $chats.scrollTop($chats.innerHeight());
            };

            var htmlEncode = function (content) {
                return $('<div />').text(content).html();
            }

            $.connection.hub.start().done(function () {
                $("#ctrl button").click(function (evt) {
                    var $name = $("#nickname"),
                        name = $name.val(),
                        $message = $("#message"),
                        message = $message.val();

                    chatHub.server.sendMessage(name, message);

                    $message.val("").focus();
                });
            });

            $(window)
                .resize(function () {
                    var h = Math.max(200, screen.availHeight - $chats.offset().top - 200);
                    $chats.height(h);
        })
            .resize();
        });
    </script>
}

1 个答案:

答案 0 :(得分:0)

在ASP.NET Webforms中没有称为section的标记。因此,基本上,您可以删除section标签。

在Web表单中,您可以使用诸如Masterpage这样的ContentPlaceholders

<asp:ContentPlaceHolder id="scripts" runat="server">
</asp:ContentPlaceHolder>

在任何使用母版页的网站中:

<asp:Content ID="Content1" ContentPlaceHolderID="scripts" Runat="Server">
    <script src="~/Scripts/jquery.signalR-2.4.0.min.js"></script>
    <script type="text/javascript" src="~/signalr/hubs"></script>
    <script type="text/javascript">
        $(function () {
            var $chats = $('#chats'),
                chatHub = $.connection.chatHub;

            chatHub.client.gotMessage = function (nickname, message) {
                $chats.append('<li><span class="label label-primary">' + htmlEncode(nickname)+'</span>' + htmlEncode(message));
                $chats.scrollTop($chats.innerHeight());
            };

            var htmlEncode = function (content) {
                return $('<div />').text(content).html();
            }

            $.connection.hub.start().done(function () {
                $("#ctrl button").click(function (evt) {
                    var $name = $("#nickname"),
                        name = $name.val(),
                        $message = $("#message"),
                        message = $message.val();

                    chatHub.server.sendMessage(name, message);

                    $message.val("").focus();
                });
            });

            $(window)
                .resize(function () {
                    var h = Math.max(200, screen.availHeight - $chats.offset().top - 200);
                    $chats.height(h);
        })
            .resize();
        });
    </script>
</asp:Content>