我在我的视图中使用了 EditorFor
。
就像这样
@Html.EditorFor(model => model.First().Link,
new { htmlAttributes = new { @class = "form-control", placeholder = "Email", id= "start" } })
同时我在控制器中编写了一个动作,它在数据库中查找所有为NULL的表格并将其更新为某个值,以下是代码:
public ActionResult Update(string start="lol")
{
ApplicationDbContext context = new ApplicationDbContext();
IEnumerable<InvitationMails> customers = context.InvitationMails
.Where(c => c.Link == null)
.AsEnumerable()
.Select(c => {
c.Link = start;
return c;
});
foreach (InvitationMails customer in customers)
{
// Set that row is changed
context.Entry(customer).State = EntityState.Modified;
}
context.SaveChanges();
return RedirectToAction("Index");
}
在索引视图中,我点击一个按钮,该按钮跳转到更新操作并启动它。
以下是代码:
<ul class="btn btn-default" style="width: 150px; list-style-type: none; font-size: 16px; margin-left: 20px">
<li style="color: white">@Html.ActionLink("Добавить почту", "Update", "InvitationMails", null, new { @style = "color:white" })</li>
</ul>
但是这里的更新是使用静态值,我想从视图中接收值。我应该如何编写我的代码?
name="start"
。既然你没有绑定任何东西,就手动创建输入吧。 - user3559349