I have searched in different forums to solve my issue..But every attempt was failed.I have modified my content with those solutions desscribed in the forum.
I have got the following controllers
Here is my view
_CommentsForm
My routemaps
So in a nutshell I need to switch to the login page and to be authenticated when replying or making comments.But here the problem is when clicked on the submit(comment) button it switches to the login page and by hitting login button it returns a
'RESOURCE NOT FOUND'exception(Home/_Submit).How can it be solved???
I have got the following controllers
public ActionResult GetMessage(Int32 id) { Breadcrumb br; Thread mythread = db.Threads.Find(id); var mycategory = db.Categories.Find(mythread.ForumID); var user = db.UserDetails.Find(mythread.UID); if (db.Comments.Where(x => x.MessageID == mythread.MessageID).Count() > 0) { ViewBag.comment = "Y"; } if (User.IsInRole("Employee") || User.IsInRole("Admin")) { ViewBag.employee = "Y"; } if (User.IsInRole("User")) { ViewBag.user = "Y"; } br = new Breadcrumb() { thread = mythread, category = mycategory, userdetail = user }; return View(br); } public PartialViewResult _GetComments(int? id) { if (User.IsInRole("Employee")||User.IsInRole("Admin")) { ViewBag.employee = "Y"; } if(User.IsInRole("User")) { ViewBag.user = "Y"; } var comments = db.Comments.Where(x => x.MessageID == id).ToList(); return PartialView(comments); } [HttpPost] [ValidateAntiForgeryToken()] [Authorize()] public ActionResult _Submit(Comment comment) { if (ModelState.IsValid) { db.Comments.Add(comment); db.SaveChanges(); return RedirectToAction("GetMessage", routeValues: new { id = comment.MessageID }); } return View(); } public PartialViewResult _GetCommentForm(Int32 id,string user) { Comment comment; if (user!="") { var n = user; var userdetails = db.UserDetails.Where(x => x.UserName == n).ToArray(); var uid = userdetails[0].UID; comment = new Comment() { AddedDate = DateTime.Now, AddedBy = user, MessageID = id, UID = uid }; return PartialView("_GetCommentForm", comment); } else { return PartialView("_GetCommentForm"); } }
Here is my view
@model MVCForum.Models.Breadcrumb<div style="width: 92%; padding-left: 0; padding-bottom: 10px; font-size: 14px;display:block;margin-left:20px"> @Model.thread.Content<a onclick="toggle()" style="cursor: pointer;text-decoration: none;padding:2px;display:block">Reply</a><div id="editor" style="display:none"> @using (Ajax.BeginForm("_Submit", "Home", new AjaxOptions() { UpdateTargetId = "comments", HttpMethod = "Post" })) { @Html.AntiForgeryToken(); @Html.Action("_GetCommentForm", "Home", routeValues: new { id = Model.thread.MessageID, user = User.Identity.Name }) }</div><div> @if (ViewBag.comment == "Y") {<div id="comments" style="padding-top: 1em;"><h3 style="padding-top: 2px;margin-top:2px;font-size:1em;font-weight:bold">All Replies</h3><br /> @Html.Action("_GetComments", "Home", routeValues: new { id = Model.thread.MessageID })</div> }</div>
_CommentsForm
@model MVCForum.Models.Comment @Html.HiddenFor(model => Model.AddedBy); @Html.HiddenFor(model => Model.MessageID); @Html.HiddenFor(model => Model.AddedDate); @Html.HiddenFor(model => Model.UID);<div style="width:990px"> @Html.TextAreaFor(model => Model.Body)<button class="btn btn-sm btn-info" type="submit">Submit</button></div>
My routemaps
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Tagging", url: "{controller}/{action}/{id}/{user}", defaults: new { controller = "Home", action = "_GetCommentForm", id = UrlParameter.Optional, user = "" } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}/{user}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
So in a nutshell I need to switch to the login page and to be authenticated when replying or making comments.But here the problem is when clicked on the submit(comment) button it switches to the login page and by hitting login button it returns a
'RESOURCE NOT FOUND'exception(Home/_Submit).How can it be solved???
Anzal