[英]C# - ASP.NET MVC - Url.Action got HTTP 404
出现错误
无法找到该资源。 说明:HTTP 404。
我正在尝试使用剃刀在MVC中执行POST方法。 在我的控制器中:
ServiceListController
public ActionResult Index()
{
return View();
}
[HttpPost]
private ActionResult GetData(string txtTech, string txtSerial, string txtJobNo)
{
return View();
}
在我中,我使用了Url.Action。 但是,当按下按钮过滤器时,无法找到请求的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>
尝试像这样使用html.beginform并公开发布方法
@using (Html.BeginForm("GetData", "ServiceList", FormMethod.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>}
尝试这个
ServiceListController
您的方法是针对
[HttpPost]
[ValidateAntiForgeryToken]
Public ActionResult GetData(string txtTech, string txtSerial, string txtJobNo)
{
return View();
}
您可以尝试两种方式的更新视图操作
1)
<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>
2)
@using (Html.BeginForm("GetData", "ServiceList", FormMethod.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>}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.