C# 将视图中的数据写入数据库中的每一行
我有这样的模型C# 将视图中的数据写入数据库中的每一行,c#,asp.net-mvc,database,asp.net-mvc-4,C#,Asp.net Mvc,Database,Asp.net Mvc 4,我有这样的模型 public class InvitationMails { [Key] public int Individ_Id { get; set; } public string From { get; set; } [Display (Name = "Почта")] public string To { get; set; } public string Subject { get; set; } public string
public class InvitationMails
{
[Key]
public int Individ_Id { get; set; }
public string From { get; set; }
[Display (Name = "Почта")]
public string To { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public string Link { get; set; }
public string Name { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? LinkStart { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? LinkEnd { get; set; }
}
我在输入日期的地方有日期选择器。
我在表格中也有电子邮件,因为我是在其他视图中写的
这里是观景台
<div class="inner-div3">
<div class="right-welcome-div2">
<div class="counterdiv3">
<div style="float: left; width: 100%; height: 100%; padding-top: 5px; background: lightgray">
<b style="text-align: center; font-size: 20px;">Время жизни ссылки</b>
</div>
</div>
<div style="width: 100%; height: 25%;">
<div style="margin-left: 50px; float: left; margin-top: 20px; height: 25%;">
<div style="margin-bottom: 20px;">
<b>Время начала </b>
<input type="text" class="form-control" id="date" placeholder="Время окончания">
</div>
</div>
<div style="margin-right: 50px; float: right; margin-top: 20px; height: 25%;">
<div style="margin-bottom: 20px;">
<b>Время окончания </b>
<input type="text" class="form-control" id="date2" placeholder="Время окончания">
</div>
</div>
</div>
<div style="width: 100%; height: 23%;">
@Html.TextBoxFor(model => model.First().Link, new { @class = "datetimepicker form-control", placeholder = "Ссылка", @style = "margin-top:35px;",id = "date" })
</div>
<div style="text-align: center">
<input type="submit" value="Генерировать" style="font-size: 16px" class="btn btn-default" />
</div>
</div>
<div class="left-welcome-div2">
<div class="counterdiv2">
<b style="text-align: center; font-size: 20px;">Список приглашений</b>
</div>
<div style="height: 60%; width: 100%; overflow: auto">
@{int rowNo = 0;}
@foreach (var item in Model)
{
<div style="margin-left: 25px; margin-top: 10px;">
<b>@(rowNo += 1)</b>
<b style="margin-left: 10px;">@Html.DisplayFor(modelItem => item.To)</b>
<a style="float: right; margin-right: 20px;" href='@Url.Action("Edit", "InvitationMails", new {id = item.Individ_Id})'>
<img src='@Url.Content("~/Images/Edit.png")' />
</a>
<a style="float: right; margin-right: 20px;" href='@Url.Action("Delete", "InvitationMails", new {id = item.Individ_Id})'>
<img src='@Url.Content("~/Images/Delete.png")' />
</a>
</div>
}
</div>
<div style="height: 20%; width: 100%">
<ul class="btn btn-default" style="width: 150px; list-style-type: none; font-size: 16px; margin-left: 20px">
<li style="color: white">@Html.ActionLink("Добавить почту", "Create", "InvitationMails", null, new { @style = "color:white" })</li>
</ul>
<ul class="btn btn-default" style="width: 150px; list-style-type: none; font-size: 16px; margin-left: 230px">
<li style="color: white">@Html.ActionLink("Отправить", "SendEmail", "InvitationMails", null, new { @style = "color:white" })</li>
</ul>
</div>
</div>
</div>
<script>
$('#date').datepicker({
format: "dd/mm/yyyy"
});
$('#date2').datepicker({
format: "dd/mm/yyyy"
});
</script>
Время жизни ссылки
Время начала
Время окончания
@Html.TextBoxFor(model=>model.First().Link,新的{@class=“datetimepicker表单控件”,placeholder=“СССща”,“margin top:35px;”,id=“date”})
Список приглашений
@{int rowNo=0;}
@foreach(模型中的var项目)
{
@(行号+=1)
@DisplayFor(modelItem=>item.To)
}
- @Html.ActionLink(“бббббббббббббббббб
- @Html.ActionLink(“аПаааааа”、“发送电子邮件”、“邀请邮件”,空,新{@style=“color:white”})
$(“#日期”).datepicker({
格式:“dd/mm/yyyy”
});
$('#date2')。日期选择器({
格式:“dd/mm/yyyy”
});
当我点击这个按钮时,我需要从日期选择器中获取日期,并在表中的所有行中输入日期。@Html.ActionLink(“ццааа”、“sendmail”、“InvitationMails”、null、new{@style=“color:white”})
我怎么能做到
非常感谢你的帮助
更新
我这样写方法,但它用静态数据更新表
如何将日期选择器的数据传输到此方法
public static void UpdateLinkStart()
{
ApplicationDbContext context = new ApplicationDbContext();
IEnumerable<InvitationMails> customers = context.InvitationMails
.Where(c => c.Link == null)
.AsEnumerable()
.Select(c => {
c.Link = "test.com";
return c;
});
foreach (InvitationMails customer in customers)
{
context.Entry(customer).State = EntityState.Modified;
}
context.SaveChanges();
}
publicstaticvoidupdatelinkstart()
{
ApplicationDbContext上下文=新的ApplicationDbContext();
IEnumerable customers=context.InvitationMails
.Where(c=>c.Link==null)
.可计算的()
.选择(c=>{
c、 Link=“test.com”;
返回c;
});
foreach(客户中的邀请邮件客户)
{
context.Entry(customer.State=EntityState.Modified;
}
SaveChanges();
}
您是在问如何使用日期时间选择器,还是在问如何将所选日期发回?否。我喜欢约会。我需要将日期发布到表中所有已经在这里的行。@Wheels 73将视图包装成一个表单,并将其发布回控制器。你们讨论过这个吗<代码>@使用(Html.BeginForm())
@wheelsys@使用(Html.BeginForm(“Action”、“Controller”、FormMethod.Post))