我是MVC5编程的初学者。 我正在使用MVC5和Entity框架6。 我有一个类和一个DateTime属性,如下所示:
public ActionResult Create([Bind(Include = "MelliCode,EnCode,grade,quota,password,FName,Lname,shenasname,FatehrName,sex,tel,mobile,ResAddress,WorkAddress")] Expert expert)
{
if (ModelState.IsValid)
{
db.Experts.Add(expert);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(expert);
}
我的控制员:
<div class="form-group">
@Html.LabelFor(model => model.BirthDay, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BirthDay, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BirthDay, "", new { @class = "text-danger" })
</div>
我的观点是这样的:
//You can replace the timeline_type with a detailed descrition as given below.
var timelineType = {
accepted: 'Accepted An Answer',
answered: 'Posted An Answer',
asked: 'Asked A Question',
badge: 'Earned A Badge',
commented: 'Posted A Comment',
reviewed: 'Reviewed A Suggested Edit',
revision: 'Edited A Post',
suggested: 'Suggested An Edit'
};
var formattedFeeds = [];
$.get('https://api.stackexchange.com/2.2/users/6778969/timeline?site=stackoverflow&filter=!))x30_z', function (feeds) {
feeds.items.forEach(function (feed) {
var formattedFeed = {};
formattedFeed.timeline_type = timelineType[feed.timeline_type];
formattedFeed.title = feed.title || feed.detail;
formattedFeed.detail = feed.detail || '';
formattedFeed.creation_date = new Date(feed.creation_date * 1000);
formattedFeeds.push(formattedFeed);
});
});
然而,在运行页面并输入数据库中的个人信息后,为生日插入null !!!为什么?
答案 0 :(得分:0)
我发现了我的问题 我在[Bind]属性
中忘记了生日public ActionResult Create([Bind(Include = "BirthDay,MelliCode,EnCode,grade,quota,password,FName,Lname,shenasname,FatehrName,sex,tel,mobile,ResAddress,WorkAddress")] Expert expert)
{
if (ModelState.IsValid)
{
db.Experts.Add(expert);
db.SaveChanges();
return RedirectToAction("Index");
}