M
M
Matsun2017-03-06 17:36:18
ASP.NET
Matsun, 2017-03-06 17:36:18

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>
                }

Here is the controller
[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");
            }
        }

Actually, the problem is that after a person adds a comment, he gets to the page
localhost:25895/articles/item-my-test-blog-url-2#leaveCommentTitle
using the redirect
return RedirectPermanent(returnUrl + "#leaveCommentTitle" ?? Url .Action("Index", "CategoryArticle"));
however, if a person does not fill in the required field, then he gets to the page
localhost:25895/articles/item-my-test-blog-url-2
how to make the second url also have an anchor #leaveCommentTitle

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Newred, 2017-04-22
@Newred

does not fill in a required field

1. On the page, check whether the field is filled using JS and do not send if it is not filled.
2. Or cling not to the topic of the comment, but to #Id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question