2
我已經創建了一個創建視圖。現在的事情是,我想將創建視圖中的所有字段放入數據以及兩個不在創建日期和視圖的其他字段由...創建。我該怎麼做?asp.net MVC創建視圖
我已經創建了一個創建視圖。現在的事情是,我想將創建視圖中的所有字段放入數據以及兩個不在創建日期和視圖的其他字段由...創建。我該怎麼做?asp.net MVC創建視圖
在從NerdDinner此示例代碼,看看評論:
// POST: /Dinners/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Dinner dinner)
{
if (ModelState.IsValid) {
try {
// here you can add your other fields:
dinner.CreatedDate = DateTime.Now;
dinner.CreatedBy = LoggedUserId; // you have to figure out how to get this
dinnerRepository.Add(dinner);
dinnerRepository.Save();
return RedirectToAction("Details", new {id = dinner.DinnerID });
}
catch {
ModelState.AddRuleViolations(dinner.GetRuleViolations());
}
}
return View(dinner);
}