title: Asp.Net MVC4 Return Date and Time from Controller to View
body: <p>I am working with Asp.Net MVC4, I need to retrieve the date and time from the server and not the client. To restore them when I must click a button in the view, for example the name of the button "Nuevo" and from the view so I defined, the event is called by javascript in Action define the controller (Home) and ActionResult (Nuevo):</p>
  
  <pre><code>&lt;script type= "text/javascript"&gt;
      function Nuevo() {
          $.ajax({
             url: '@Url.Action("Nuevo", "Home")',
             type: 'POST',
             contentType: 'application/json; charset=utf-8',
             dataType: 'json',
             data: JSON.stringify({ }),
             success: function () {}
          });
       }
  &lt;/script&gt;
  </code></pre>
  
  <p>On receipt the data controller in the New ActionResult as follows:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Nuevo()
  {
       Persona persona = new Persona();
       persona.Fecha = DateTime.Now;
       persona.Hora = DateTime.Now;
       return View(persona);
  }
  </code></pre>
  
  <p>This is my view, I use typed views:</p>
  
  <pre><code>@model MvcJavaScript.Models.Persona
  &lt;script type= "text/javascript"&gt;
      function Nuevo() {
          $.ajax({
              url: '@Url.Action("Nuevo", "Home")',
              type: 'POST',
              contentType: 'application/json; charset=utf-8',
              dataType: 'json',
              data: JSON.stringify({}),
              success: function (data) {
              }
          });
      } 
  &lt;/script&gt;
  &lt;h2&gt;Registro persona&lt;/h2&gt;
  @using (Html.BeginForm("", "", FormMethod.Post, new { id = "formPersona" })){ 
     &lt;table cellpadding="4" class="td.headerTabsColor"&gt;
       &lt;tbody&gt;
         &lt;tr&gt;
               &lt;td&gt;&lt;label&gt;Fecha : &lt;/label&gt;@Html.TextBoxFor(u =&gt; u.Fecha, new { sololectura = true })&lt;/td&gt; 
         &lt;/tr&gt; 
         &lt;tr&gt;
           &lt;td&gt;&lt;label&gt;Sexo : &lt;/label&gt;@Html.TextBoxFor(u =&gt; u.Sexo, new { style = "width:225px", sololectura = false })&lt;/td&gt;
         &lt;/tr&gt;
         &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;Hora : &lt;/label&gt;@Html.TextBoxFor(u =&gt; u.Hora, new { sololectura = true })&lt;/td&gt;  
         &lt;/tr&gt;
       &lt;/tbody&gt;
    &lt;/table&gt;
  }
  </code></pre>
  
  <p>What I need to do is to insert a new record (by clicking on the button "Nuevo") I load the default server time and date in different textbox.</p>
  
  <p>Running this example enters the New ActionResult but to return to the data to view the TextBox is void, I tried other fields and the same result.</p>
  
  <p>Any suggestions or help with this problem.</p>
  
  <p>regards</p>
  
  <p>Ricardo</p>