【发布时间】:2018-10-31 18:35:48
【问题描述】:
我有一个表,其中包含指向控制器中方法的链接。 该表位于带有提交按钮的表单中。
以下是我的看法:
@using (Html.BeginForm("SaveClient", "Client", FormMethod.Post))
{
@Html.AntiForgeryToken()
string language = ViewBag.Language;
<div class="table-wrapper">
<table width="100%">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Client.ClientCode)
</th>
<th>
@Html.DisplayNameFor(model => model.Client.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Client.Surname)
</th>
<th>
@Html.DisplayNameFor(model => model.Client.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Client.ContactNumber)
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.ClientMatches)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ClientCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Surname)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.ContactNumber)
</td>
<td>
<button onclick="location.href='@Url.Action("ShowClient", "Client", new { id=item.ClientCode})'">
<i class="icon-arrow-right"></i>
</button>
</td>
</tr>
}
</tbody>
</table>
</div>
@Html.HiddenFor(m => m.Client.Surname, Model.Client.Surname)
@Html.HiddenFor(m => m.Client.Name, Model.Client.Name)
@Html.HiddenFor(m => m.Client.ContactNumber, Model.Client.ContactNumber)
@Html.HiddenFor(m => m.Client.Email, Model.Client.Email)
@Html.HiddenFor(m => m.Client.Comments, Model.Client.Comments)
<div class="mdl-card__actions centered">
<button>
Create New
</button>
</div>
}
我在 ClientController 中的 ShowClient 方法:
public ActionResult ShowClient(string clientCode)
{
if (clientCode == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
*some other actions*
}
当我单击“新建”按钮时,它工作正常。但是,当我单击表中的 Url.Action 时,我的 ShowClient 方法没有被命中。 知道我可能做错了什么吗? 谢谢
【问题讨论】:
标签: c# get url.action