Razor Ajax Helper does not replacing UpdateTargetId

本文关键字:replacing UpdateTargetId not does Ajax Helper Razor | 更新日期: 2023-09-27 18:01:12

我有这个Ajax Begin Form

using (Ajax.BeginForm("ShowAllComments", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "CommentsList" }))
        {
            <div class="form-horizontal">
                <div class="form-group" style="visibility:hidden;height:3px;width:3px;">
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" required id="article_id" name="article_id" type="text" value="@Model.news.id" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="article_id" data-valmsg-replace="true"></span>
                    </div>
                </div>
                <input class="show_all_comments" type="submit" value="Show All Comments.." />
            </div>
        }  

哪个发送邮件到这个方法

[HttpPost]
    public ActionResult ShowAllComments(int article_id)
            {
                    var innerJoinQuery =
                    (from comment in db.Set<Comment>()
                     join person in db.Set<Person>() on comment.create_user equals person.id
                     where comment.accepted && comment.category == 2 && comment.place_id == article_id
                     select new CommentView { userfullname = person.firstname + " " + person.lastname, description = comment.description, create_date = comment.create_date }).OrderBy(x => x.create_date).ToList();
                    masterlayout.comment_view_list = innerJoinQuery;
                    return PartialView("_CommentsList", masterlayout);
            }

这个(_CommentsList(部分视图

@model Spearfishing.Data.MasterLayoutView
<div id="CommentsList">
    @foreach (var item in Model.comment_view_list)
    {
        <div class="comment">
            <div class="comment_user">@item.userfullname</div>
            <div class="comment_descr">@Html.Raw(item.description)</div>
            <div class="comment_date"><i class="fa fa-calendar" aria-hidden="true"></i> @item.create_date.ToString("dd/MM/yy - HH:mm")</div>
        </div>
    }
</div>

问题是我的Ajax。BeginFrom不替换updatetargetid->CommentsList。。相反,它在CommentsListdiv中添加了一个新的div。。带id注释列出类似于<div id="CommentsList"><div id="CommentsList"> 的内容

有人能帮帮我吗。。我的错在哪里?

Razor Ajax Helper does not replacing UpdateTargetId

尝试更改InsertionMode。替换为InsertionMode。替换为:(

在Ajax中。BeginForm添加htmlAttributes:id="CommentsList">

在_CommentsList中删除(<div id="CommentsList"><div id="CommentsList">(

@model Spearfishing.Data.MasterLayoutView
    @foreach (var item in Model.comment_view_list)
    {
        <div class="comment">
            <div class="comment_user">@item.userfullname</div>
            <div class="comment_descr">@Html.Raw(item.description)</div>
            <div class="comment_date"><i class="fa fa-calendar" aria-hidden="true"></i> @item.create_date.ToString("dd/MM/yy - HH:mm")</div>
        </div>
    }

这将替换表单标签

中的html