Answer the question
In order to leave comments, you need to log in
How to send user to route with anchor?
In the view of the page with the article there is a form
@using (Html.BeginForm("ShowOne", "Category"))
{
<div class="inputFields">
<div class="fieldItem textField author">
<p class="fieldName">Ваше имя @Html.ValidationMessage("Author")</p>
@Html.TextBox("Author", "", new { placeholder = "Имя" })
</div>
<div class="fieldItem textField email">
<p class="fieldName">Ваш email</p>
@Html.TextBox("Email", "", new { placeholder = "Email" } )
</div>
<div class="fieldItem areaField fulltext">
<p class="fieldName">Комментарий: @Html.ValidationMessage("FullText")</p>
@Html.TextArea("FullText", "", 5, 20, new { placeholder = "Текст комментария" })
</div>
<div class="buttons">
<input type="submit" value="Отправить" class="butSubmit submitComment" />
<input type="button" value="Отмена" class="clearSubmit clearComment" />
</div>
@Html.Hidden("ArticleId", Model.ArticleId)
@Html.Hidden("returnUrl", Request.Url.PathAndQuery)
</div>
}
[HttpPost]
public ActionResult ShowOne(Comment comment, string returnUrl, int ArticleId = 0, int ParentID = 0)
{
if(ArticleId != 0)
{
Article one = service.Repository.GetPost(ArticleId);
if (ModelState.IsValid)
{
comment.DatePublication = DateTime.Now;
comment.Article = one;
comment.ParentId = ParentID;
service.Repository.SaveComment(comment);
TempData["message"] = string.Format("Выш комментарий добавлен");
return RedirectPermanent(returnUrl + "#leaveCommentTitle" ?? Url.Action("Index", "CategoryArticle"));
}
else
{
return View("ShowOne", one);
}
}
else
{
return View("Error");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question