我需要将选定的表行值从一个视图传递到另一个视图。 我的代码看起来像这样。
<table id="tableid">
<thead>
<tr>
<th id="Sno">S No</th>
<th>Name</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >
@foreach (var sd in Model.Details)
{
<tr id="trid">
<td>@sd .Id</td>
<td>@sd .Name</td>
<td>@sd .Status</td>
<td>
<a id="actionId" onclick="Clickfn(@sd .Id)" >
</a>
<script>
function Clickfn(Id) {
var url = '@Url.Action("UpdateCam", "Campaignboard", new {id = -1})';
window.location.href = url.replace('-1', Id);
}
</script>
</td>
</tr>
}
</tbody>
</table>
我想将此视图中的选定行详细信息传递到另一个视图。 我怎么能做到这一点。
答案 0 :(得分:1)
只需使用ActionLink帮助程序(并转储javascript)
@foreach (var sd in Model.Details)
{
....
<td>@Html.ActionLink("SomeTextLabel", "UpdateCam", "Campaignboard", new { id = sd .Id })</td>
...
}
答案 1 :(得分:0)
你可以追加字符串。
var url = '@Url.Action("UpdateCam", "Campaignboard")';
window.location.href = url + '/' + Id;
默认情况下,根据路由配置,查询将路由到id
。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
答案 2 :(得分:0)
function Clickfn(Id, Name, Status)
{
var url = "@Url.Action("UpdateCam", "Campaignboard", new {id = _Id, name=_Name, status=_Status})".replace("_Id", Id).replace("_Name", Name).replace("_Status", Status);
window.location.href = url;
}
你的行动将是,
Public ActionResult UpdateCam(int id, string name, string status)
{
// TODO
}