gpt4 book ai didi

jquery - 在 mvc4 中调用从 View 中删除帖子?

转载 作者:行者123 更新时间:2023-12-01 07:18:47 26 4
gpt4 key购买 nike

我正在尝试从 View 中调用[HttpPost]Delete。单击我想要加载 jQuery 对话框并调用 post 操作方法。

它似乎正在寻找我删除的删除 View 。我只是保留了 [HttpPost] 的代码来处理。

索引 View

 <ul class="dropdown-menu">
@{
@Html.TryPartial("_actions", model)
<li> @Html.ActionLink("Edit", "Edit", new {id =model.Id})</li>
<li class="divider"></li>
<li>@Html.ActionLink("Delete", "Delete", new {id =model.Id},new { @class = "delete-link" })</li>
}
</ul>

Controller

 [HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(Byte[] id)
{

var committeeMember = db.Committee_Member.FirstOrDefault(x => x.Committee_Member_Id == id);

if (committeeMember != null)
{
committeeMember.Cancelled = 1;
db.Entry(committeeMember).State = EntityState.Modified;
db.SaveChanges();
Success("Your activity was deleted!");
return RedirectToAction("Index", new { id = committeeMember.Customer_Number });
}

Error("there were some errors in your form.");
return RedirectToAction("Index");
}

一旦我单击 Delete 链接页面,就会自动重定向到 Delete View ,而无需 jQuery 对话框。

网址是 http://company.com:55253/Member/Delete/AAAAAAICyns%3d

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Member/Delete/AAAAAAICyns=

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

如何直接调用删除帖子而不重定向?

最佳答案

您正在使用 GET 而不是 POST 执行操作。

尝试

@using (Html.BeginForm()) {
<input type="submit" value="Delete" />
@Html.HiddenFor(m => m.Id)
}

代替

@Html.ActionLink("Delete", "Delete", new AjaxOptions { HttpMethod = "POST"}, 
new { @class = "delete-link" , id =model.Id })

关于jquery - 在 mvc4 中调用从 View 中删除帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16069244/

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