这是我的看法:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ExpireDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ExpireDate)
@Html.ValidationMessageFor(model => model.ExpireDate)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
(基本上是模板视图)
这是我发布到的 C#:
[HttpPost]
public ActionResult Create(bulletin newBulletin)
{
try
{
var db = Util.GetDb();
var toAdd = new bulletin
{
title = newBulletin.title,
description = newBulletin.description,
expire_date = newBulletin.expire_date,
timestamp = DateTime.Now,
user_id = 1
};
db.bulletins.InsertOnSubmit(toAdd);
db.SubmitChanges();
return RedirectToAction("Index");
}
catch(Exception ex)
{
return View();
}
}
标题和说明已填充,但无论我在 expire_date 文本框中输入什么日期,它都是:
{1/01/0001 上午 12:00:00}
有什么线索吗?