我有这个:
foreach (var user in Model.Users){
<tr>
<td>
<a href="#name" class="portfolio-link" data-toggle="modal">user.UserName</a>
</td>
</tr>}
并且需要将id(@ user.id)发送到
<div class="portfolio-modal modal fade" id="email" tabindex="-1" role="dialog" aria-hidden="true">
@using (Html.BeginForm("ChangeName", "Person"))
{
<div class="form-group">
@Html.LabelFor(Model => Model.Person.UserName, "Jméno", htmlAttributes: new { @class = "control-label align-center" })
<div class="col-md-12">
@Html.EditorFor(Model => Model.Person.UserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(Model => Model.Person.UserName, " ", new { @class = "text-danger " })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Upravit" class="btn btn-success" />
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Zavřít</button>
</div>
</div>
}
然后将其发送给控制器。
我需要在控制器中使用id作为正确的用户。 有人有什么想法吗?
答案 0 :(得分:0)
您可以使用隐藏字段在其中存储用户ID值,以将用户ID推送到控制器操作。 例如
@Html.HiddenFor(model => model.User.Id)
或
<input type="hidden" id="UserId" value="@user.id"/>
答案 1 :(得分:0)
在此代码Id = 1中为每个人
<td>
<a href="#name" class="portfolio-link" data-toggle="modal"><input type="hidden" id="UserId" value="@user.Id" />@user.UserName</a>
<div class="portfolio-modal modal fade" id="name" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-content">
<div class="close-modal" data-dismiss="modal">
<div class="lr">
<div class="rl">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="modal-body">
<h2>Změna jména @user.Id</h2>
<hr class="star-primary">
@using (Html.BeginForm("ChangeName", "Person", new { id = user.Id }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal center-block">
<div class="col-md-10">
<h4>Zadej nové jméno</h4>
<hr />
<div class="form-group">
@Html.LabelFor(model => model.User.UserName, "Jméno", htmlAttributes: new { @class = "control-label align-center" })
<div class="col-md-12">
@Html.EditorFor(model => model.User.UserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.User.UserName, " ", new { @class = "text-danger " })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Upravit" class="btn btn-success" />
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Zavřít</button>
</div>
</div>
</div>
</div>
}
</div>
</div>
</div>
</div>
</div>
</div>