@model MvcAsyncChat.RequestModels.EnterRequest @{ View.Title = "Enter"; Layout = "~/Views/Shared/_Layout.cshtml"; } @section Head {} <tr> <td> <h2>[MVC聊天]是使用ASP.NET MVC 3的异步聊天室 <table> <tr> <td> <fieldset> <legend>进入聊天室</legend> @using(Html.BeginForm()) { @Html.EditorForModel() <input type="submit" value="Enter" /> } </fieldset> </td> </tr> </table> </td> </tr> @section PostScript { <script> $(document).ready(function() { $("#Name").focus(); }); </script> }
Room.cshtml
@using MvcAsyncChat; @using MvcAsyncChat.RequestModels; @model SayRequest @{ View.Title = "Room"; Layout = "~/Views/Shared/_Layout.cshtml"; } @section Head { <script src="https://www.jb51.net/@Url.Content("~/Scripts/room.js")"></script> } <tr> <td></td> </tr> <tr> <td> <label for="actionsList">操作:</label> <ul> <li>@Html.RouteLink("离开房间", RouteName.Leave)</li> </ul> @using (Ajax.BeginForm("say", new { }, new AjaxOptions() { OnFailure = "onSayFailed", OnSuccess = "onSay", HttpMethod = "POST", }, new { id = "sayForm"})) { @Html.EditorForModel() } </td> </tr> @section PostScript { <script> $(document).ready(function() { $("#Text").attr("placeholder", "你说:"); $("#Text").focus(); setSayHandler(); getMessages(); }); </script> }
运行结果如图: