【发布时间】:2017-03-10 08:39:24
【问题描述】:
我的视图中有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>
但这里是静态值更新,我想从 VIew 接收值。 我需要如何编写代码?
【问题讨论】:
-
为什么你有一个模型,它是一个集合,并试图绑定到与你的模型无关的东西。目前尚不清楚您要达到的目标。为了绑定到您的参数,您的输入需要
name="start"。由于您没有绑定任何东西,只需手动创建输入 -
然后您显示了一个操作链接,该链接似乎正在对您的方法进行 GET,但这并没有传递您输入的值。
标签: c# asp.net asp.net-mvc linq