Bladeren bron

评论留言优化

懒得勤快 4 jaren geleden
bovenliggende
commit
4ff4cdbc59

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/MsgController.cs

@@ -54,7 +54,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// 留言板
         /// </summary>
         /// <returns></returns>
-        [ResponseCache(Duration = 600, VaryByHeader = "Cookie"), Route("msg")]
+        [Route("msg"), Route("msg/{cid:int}"), ResponseCache(Duration = 600, VaryByHeader = "Cookie")]
         public async Task<ActionResult> Index()
         {
             ViewBag.TotalCount = LeaveMessageService.Count(m => m.ParentId == 0 && m.Status == Status.Published);

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -64,7 +64,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="id"></param>
         /// <param name="kw"></param>
         /// <returns></returns>
-        [Route("{id:int}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "id" }, VaryByHeader = "Cookie")]
+        [Route("{id:int}"), Route("{id:int}/comments/{cid:int}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "id" }, VaryByHeader = "Cookie")]
         public async Task<ActionResult> Details(int id, string kw)
         {
             var post = await PostService.GetAsync(p => p.Id == id && (p.Status == Status.Published || CurrentUser.IsAdmin)) ?? throw new NotFoundException("文章未找到");

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Msg/Index.cshtml

@@ -2,7 +2,7 @@
 @{
     ViewBag.Title = "留言板";
     Layout = "~/Views/Shared/_Layout.cshtml";
-    string cid = string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"].ToString();
+    var cid = Context.Request.RouteValues["cid"]??(string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"]);
     string hidden = string.IsNullOrEmpty(Context.Request.Cookies["ValidateKey"]) ? "" : "hidden";
 }
 <link href="~/Assets/layui/css/layui.min.css" rel="stylesheet" />

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Msg/Index_Admin.cshtml

@@ -5,7 +5,7 @@
     ViewBag.Title = "留言板";
     Layout = "~/Views/Shared/_Layout.cshtml";
     UserInfoDto user = Context.Session.Get<UserInfoDto>(SessionKey.UserInfo);
-    string cid = string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"].ToString();
+    var cid = Context.Request.RouteValues["cid"]?? (string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"]);
 }
 <link href="~/Assets/layui/css/layui.min.css" rel="stylesheet" />
 <script src="~/Assets/layui/layui.all.js"></script>

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Post/Details.cshtml

@@ -11,7 +11,7 @@
     ViewBag.Title = Model.Title;
     Layout = "~/Views/Shared/_Layout.cshtml";
     string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
-    string cid = string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"].ToString();
+    var cid = Context.Request.RouteValues["cid"]??(string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"]);
     string hidden = string.IsNullOrEmpty(Context.Request.Cookies["ValidateKey"]) ? "" : "hidden";
     Advertisement ad = ViewBag.Ads;
 }

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Post/Details_Admin.cshtml

@@ -14,7 +14,7 @@
     Layout = "~/Views/Shared/_Layout.cshtml";
     string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
     UserInfoDto user = Context.Session.Get<UserInfoDto>(SessionKey.UserInfo);
-    string cid = string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"].ToString();
+    var cid = Context.Request.RouteValues["cid"]??(string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"]);
     Advertisement ad = ViewBag.Ads;
 }
 <script src="https://cdn.staticfile.org/jqueryui/1.12.1/jquery-ui.min.js" async defer></script>