【发布时间】:2017-11-10 18:42:57
【问题描述】:
有一个错误
找不到资源。 说明:HTTP 404。
我正在尝试使用 razor 在我的 MVC 中执行 POST 方法。在我的控制器中:
ServiceListController
public ActionResult Index()
{
return View();
}
[HttpPost]
private ActionResult GetData(string txtTech, string txtSerial, string txtJobNo)
{
return View();
}
我使用了 Url.Action。但是当按下按钮过滤器时,Requested URL: /ServiceList/GetData 资源找不到。我需要添加到路线或其他东西吗?
<form action="@Url.Action("GetData", "ServiceList")" method="post">
@Html.AntiForgeryToken()
<table style="width: 400px">
<td>
@Html.Label("Technician", new { style = "width: 50px;" })
<input type="text" id="txtTech" name="txtTech" class="form-control" style="width: 200px" />
</td>
<td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
<td>
@Html.Label("Serial", new { style = "width: 50px;" })
<input type="text" id="txtSerial" name="txtSerial" class="form-control" style="width: 200px" />
</td>
<td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
<td>
@Html.Label("Job No", new { style = "width: 50px;" })
<input type="text" id="txtJobNo" name="txtJobNo" class="form-control" style="width: 200px" />
</td>
<td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
<td>
@Html.Label("a", new { style = "visibility: hidden;" })
@Html.DropDownList("txtStatus", new SelectList(Enum.GetValues(typeof(wmssoft_srm.Models.Status))), "Status", new { @class = "form-control", style = "width: 200px;" })
</td>
</tr>
....
<tr>
<td>
<button class="btn btn-info" type="submit" id="btFilter">Clear Filter</button>
</td>
</tr>
</table>
</form>
【问题讨论】:
-
因为你
[HttpPost]方法是private- 让它public -
将 GetData 方法私有 sccess 说明符更改为 public。
-
@StephenMuecke 非常感谢!没注意。
-
@AjasAju 你确定吗?
-
@SeM.Nop.i 编辑了我的答案。这是一个错误的想法。
标签: c# asp.net-mvc asp.net-mvc-4 razor