gpt4 book ai didi

ajax - 我如何在我的 asp.net mvc web 应用程序中使用 Ajax.beginform 更新两个 DOM 元素

转载 作者:行者123 更新时间:2023-12-04 05:55:28 25 4
gpt4 key购买 nike

我有以下 ajax.actionlink :-

<div id ="link">
@Ajax.ActionLink("Add New Answer", "Create", "Answer",
new { questionid = Model.QuestionID },
new AjaxOptions
{

HttpMethod = "Get",
UpdateTargetId = "link",
InsertionMode = InsertionMode.InsertAfter,
LoadingElementId = "progress"

})
</div>

上面的链接将重新运行以下包含 Ajax.Actionlink 的 _answer 部分 View :-
 @using (Ajax.BeginForm("Create", "Answer", new AjaxOptions
{
HttpMethod = "Post",
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "incrementanswer",
}))

{
<div id = "returnedquestion">
@Html.ValidationSummary(true)

<fieldset>
<legend>Answer here</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IsRight)
</div>
<div class="editor-field">
@Html.DropDownList("IsRight", String.Empty)
@Html.ValidationMessageFor(model => model.IsRight)
</div>
</fieldset>
<input type= "hidden" name = "questionid" value = @ViewBag.questionid>
<input type= "hidden" name = "assessmentid" value = @ViewBag.assessmentid>
<input type="submit" value="Add answer" />
</div>
}
</div>

当前单击提交按钮后,“UpdateTargetId =”incrementanswer”将随提交结果更新,但问题是我还需要删除当前的 _answer 部分 View (当前包含我插入的值的 View )点击提交后仍会显示ajax.beginform)

最佳答案

将您的部分 View 加载到包装器 div 中

<div id="partialWrapper">
@Html.partial("yourpartial")
</div>

声明 OnSuccess事件处理程序
@using (Ajax.BeginForm("Create", "Answer", new AjaxOptions
{
HttpMethod = "Post",
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "incrementanswer",
OnSuccess="removePartial"
}))

定义 removePartial
<script>
function removePartial(){
$("#partialWrapper").remove();
}
</script>

关于ajax - 我如何在我的 asp.net mvc web 应用程序中使用 Ajax.beginform 更新两个 DOM 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9556913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com