本文介绍了找不到请求网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这样做:
http://localhost:53072/Employee/Delete/2
那是我的动作:
[HttpPost]
public ActionResult Delete(int id)
{
_provider.Delete(id);
return View();
}
为什么它在控制器操作删除"中不触发?
Why does it not trigger in the controllers action Delete?
推荐答案
假设您正在通过浏览器访问url,它将发出GET
请求,而您的操作是POST
.
Assuming you are accessing the url via a browser it will make a GET
request and your action is a POST
.
您可以使用诸如fiddler之类的工具来更改您的请求,也可以改为以下方法:
You could either change your request using a tool like fiddler or change your method to this instead:
[HttpGet]
public ActionResult Delete(int id)
{
_provider.Delete(id);
return View();
}
您也可以省略[HttpGet]
,因为它是默认设置.
You could also omit the [HttpGet]
as it is the default.
更新
要使该帖子成为帖子而不是使用ActionLink,您可以执行以下操作:
In order to make this a post instead of using an ActionLink you could do the following:
将此添加到您的视图中,将其包装在开始表单中
Add this to your view, wrapping it in a begin form
@using(Html.BeginForm("Delete", "Controller", FormMethod.Post))
{
@Html.HiddenFor(m => m.Id)
<input type="submit" value="delete" />
}
请按照以下步骤操作:
[HttpPost]
public ActionResult Delete(int id)
{
_provider.Delete(id);
return View();
}
这篇关于找不到请求网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!