我使用 MvcScaffolding 为我创建 CRUD 文件。我有这个cs类:
public class addresses
{
/* Some code */
public DateTime date_created { get; set; } /* I need to access this */
public DateTime date_modified { get; set; } /* And this */
}
我需要访问date_created
变量。我想在为我创建的控制器 (c#) 或_CreateOrEdit.cshtml
创建的文件中访问它。先感谢您。
编辑
例如,我想在这里访问它
public class addressesController : Controller
{
private SoccerContext context = new SoccerContext();
//
// GET: /addresses/Create
public ActionResult Create()
{
我想在这里访问它以将其设置为当前时间
ViewBag.PossibleUsers = context.users;
ViewBag.PossibleContacts = context.contacts;
return View();
}
//
// POST: /addresses/Create
[HttpPost]
public ActionResult Create(addresses addresses)
{
if (ModelState.IsValid)
{
context.addresses.Add(addresses);
context.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.PossibleUsers = context.users;
ViewBag.PossibleContacts = context.contacts;
return View(addresses);
}
//More code............