How to Register a Date in My Database using ASP.NET MVC

Asked

Viewed 90 times

-1

Let’s assume that I want to register an item in my database.knowing my item name and price. But I also want when registering the item should also register the date.How do I do this? I’m still new to Asp.net Mvc

MODEL
     public class TABLE
        {
            [Key]
            public int IdApp { get; set; }
            public string AppName { get; set; }
            public DateTime Data { get; set; }
            public int Size { get; set; }
            public double Price { get; set; }
            public byte[] FotoByte { get; set; }
            [NotMapped]
            [Required(ErrorMessage = "O Campo da foto está Vazio")]
            public HttpPostedFileBase foto { get; set; }

        }

VIEW

@model Store.Models.CadastroApp.TABLE

@{
    ViewBag.Title = "RecordApp";
}
<link href="~/Content/css/RecordApp/index.css" rel="stylesheet" />

<div class="container">
    <div class="container">
        <div class="jumbotron">
            <h2>App Register</h2><br />
            <div class="">
               @Html.TextBoxFor(x=>x.AppName, new  {@class="form-control",@placeholder="informa o nome do App" })<br />
                @Html.TextBoxFor(x=>x.Price,new  { @class = "form-control",@placeholder="informa o preço"})<br />
                @Html.TextBoxFor(x => x.foto, new { type = "file" })
                @Html.ValidationMessageFor(x => x.foto)
            </div>
        </div>

    </div>   
</div>

1 answer

2


Do you want the date of the time of registration? If this is it you can do directly in your INSERT, keep the Data property as you already have to return the data.

SQL Server - INSERT INTO TABELA (Data) Values (GETDATE());
Oracle - INSERT INTO TABELA (Data) Values (SYSDATE());
MySQL - INSERT INTO TABELA (Data) Values (NOW());
  • Yes I want it to register me right to date at the time of registration. The way you explained is kind of spindle,because in the case I’m using Entity.

  • Then in this case, in the Actionresult that will perform the registration you assign TABLE. Data = = Datetime.Now; before executing the save method.

  • Thanks @Alexsandro.was helpful in your reply

Browser other questions tagged

You are not signed in. Login or sign up in order to post.