-4

我使用 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............
4

1 回答 1

1

您可以像这样获得访问权限:

var addr = new addresses();
var created = addr.date_created;
//same for date_modofied
于 2013-07-03T23:17:46.720 回答