C# .NET MVC Razor Post操作-服务器在'/';
我正在尝试修复其他人代码中的“应用程序“/”中的服务器错误。我假设他们试图做一些聪明的事情,但从来没有让它起作用,或者某些事情已经改变,使它停止工作。然而,我不知道它是否有效 让我向您展示代码并解释行为,希望有人能帮助我解决这个问题。先谢谢你 代码 表单上有一个删除按钮:C# .NET MVC Razor Post操作-服务器在'/';,c#,asp.net-mvc,razor,http-post,C#,Asp.net Mvc,Razor,Http Post,我正在尝试修复其他人代码中的“应用程序“/”中的服务器错误。我假设他们试图做一些聪明的事情,但从来没有让它起作用,或者某些事情已经改变,使它停止工作。然而,我不知道它是否有效 让我向您展示代码并解释行为,希望有人能帮助我解决这个问题。先谢谢你 代码 表单上有一个删除按钮: <a href='@Url.Action("Delete", new { queryId = uq.Id })' class="button small" title="Click to delete this que
<a href='@Url.Action("Delete", new { queryId = uq.Id })' class="button small" title="Click to delete this query">Delete</a>
但执行永远不会进入方法。相反,我收到了以下信息
尝试
因此,我从href链接和控制器中删除了queryId参数,并将其作为一个操作(而不是帖子)。以下是我的测试代码:
<a href='@Url.Action("Delete")' class="button small" title="Click to delete this query">Delete</a>
有谁能告诉我参数传递代码有什么问题,导致它找不到控制器方法吗?除非在表单下,否则无法执行HttpPost 阅读代码时,删除按钮似乎不在表单中,这就是它抛出404错误的原因 将动作动词从HttpPost替换为HttpGet:
[HttpGet] //Change this from HttpPost to HttpGet.
public ActionResult Delete(int? queryId)
{
var userId = CurrentUser.Id;
UserQueryService uqs = new UserQueryService();
uqs.Delete(userId, (int)queryId);
return View("Index", new UserQueryService().GetByUserId(userId));
}
查看此帖子()您的操作属于post类型,在执行get REQUEST时,删除操作正在更改数据。这应该是一篇文章,而不是一篇文章
//test method
public ActionResult Delete()
{
var userId = CurrentUser.Id;
UserQueryService uqs = new UserQueryService();
return View("Index", new UserQueryService().GetByUserId(userId));
}
[HttpGet] //Change this from HttpPost to HttpGet.
public ActionResult Delete(int? queryId)
{
var userId = CurrentUser.Id;
UserQueryService uqs = new UserQueryService();
uqs.Delete(userId, (int)queryId);
return View("Index", new UserQueryService().GetByUserId(userId));
}