我有一个编辑视图,在我对另一个视图中的表中的记录单击编辑按钮后,需要为其文本框分配一些字段。
<tbody>
@foreach (var client in this.Model.ClientsList)
{
<tr>
<td>@client.Name</td>
<td>@client.PhoneNo</td>
<td>@client.Address</td>
<td>@client.ProjectNo</td>
<td class="text-center">
<a href="../Downloads/Clients/@client.Logo" target="_blank">
<i class="fa fa-file-text"></i>
</a>
</td>
<td>@Html.ActionLink("Edit", "Edit")</td>
</tr>
}
</tbody>
这是“编辑”视图
@using (Html.BeginForm("Edit","Clients", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Clients</h4>
<hr />
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Address, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Address)
@Html.ValidationMessageFor(model => model.Address)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PhoneNo, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PhoneNo)
@Html.ValidationMessageFor(model => model.PhoneNo)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Logo, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Logo)
@Html.ValidationMessageFor(model => model.Logo)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ProjectNo, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProjectNo)
@Html.ValidationMessageFor(model => model.ProjectNo)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
我尽了最大努力,但未能做到。所以在这里问。我也尝试将其放置为对象,但这也没有用。我知道可以通过查询字符串共享它,但这不是很有效。
答案 0 :(得分:1)
您可以通过这种方式
@Html.ActionLink("Edit", // <-- Link text
"url/GetClientDataById/2" // <-- Action Method Name
)
首选方式
@Html.ActionLink("Edit", "url/GetClientDataById", new { Id = client.Id })
public string GetClientDataById(int Id)
{
//perform your DB logic here and then return your object to view
}
答案 1 :(得分:1)
我假设您要编辑客户端数据,这样就可以通过将TModelValue作为第三个参数传递给另一个视图,从而将数据传递给另一个视图
@Html.ActionLink("Edit","Edit", new { ID = client.Id })
希望它会有所帮助。 会