title: onclick button save data .cshtml
body: <p>I have a asp.net mvc razor file. The button needs to send data to the database. This is the code I have. The database is connected and working on a server. I just can't get the button to send the data to the database. An onclick event with javascript I have tried but nothing seems to work. Could someone explain what I should do? It's my first time working with .cshtml and I don't really know how to solve this problem.</p>
  
  <p>PROBLEM IS SOLVED.
  I was using the wrong names.. I referred in the C# part of the .cshtml to the id of the input and not the name..</p>
  
  <pre><code>@{
  Validation.RequireField("achternaam", "Achternaam is verplicht.");
  Validation.RequireField("voornaam", "Voornaam is verplicht.");
  Validation.RequireField("organisatie", "Organisatie is verplicht.");
  Validation.RequireField("email", "Email is verplicht.");
  Validation.RequireField("datum", "Datum is verplicht.");
  Validation.RequireField("tijd", "Tijd is verplicht.");
  
  var achternaam = "";
  var voornaam = "";
  var organisatie = "";
  var email = "";
  var datum = "";
  var tijd = "";
  
  if (IsPost &amp;&amp; Validation.IsValid())
  {
      achternaam = Request.Form["achternaam"];
      voornaam = Request.Form["voornaam"];
      organisatie = Request.Form["organisatie"];
      email = Request.Form["email"];
      datum = Request.Form["datum"];
      tijd = Request.Form["tijd"];
  
  
      using (var db = new Blub._1.Database.blubEntities())
      {
          // Insert
          var bezoeker = new Blub._1.Database.visitor
          {
              AchterNaam = achternaam,
              VoorNaam = voornaam,
              Bedrijf = organisatie,
              DatumBezoek = Convert.ToDateTime(datum),
              Email = email
          };                   
  
      Response.Redirect("~Bezoeker");
  }
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;div id="header"&gt;
      &lt;h1&gt;Als voorbeeld ...&lt;/h1&gt;
  &lt;/div&gt;
  
  &lt;div id="nav"&gt;
      &lt;br /&gt;
      &lt;a href="/OverzichtWerknemer"&gt;Overzicht&lt;/a&gt;
      &lt;br /&gt;
      &lt;a href="/Bezoeker"&gt;Nieuwe bezoeker&lt;/a&gt;
      &lt;br /&gt;
      &lt;a href="/Contractor"&gt;Nieuwe contractor&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;div id="section"&gt;
      &lt;form name="login" action="~/OverzichtWerknemer.cshtml" method="post" accept-charset="utf-8"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;b&gt;Achternaam*:&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input id="achternaam" name="LastName" type="text" maxlength="60" style="width:146px; border:1px solid #999999" required /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;b&gt;Voornaam*:&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input id="voornaam" name="FirstName" type="text" maxlength="60" style="width:146px; border:1px solid #999999" required/&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;b&gt;Organisatie*:&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input id="organisatie" name="Organization" type="text" maxlength="60" style="width:300px; border:1px solid #999999" required /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;b&gt;Emailadres*:&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input id="email" name="FromEmailAddress" type="text" maxlength="60" style="width:300px; border:1px solid #999999" required/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;b&gt;Dag van bezoek*:&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input id="datum" name="FromDate" type="date" style="width:300px; border:1px solid #999999" required /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;b&gt;Tijdstip*&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input id="tijd" name="TimeVisit" type="time" maxlength="60" style="width:300px; border:1px solid #999999" required /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="2"&gt;
                      &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      * - Verplicht veld. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;input type="submit" value="Registreer" /&gt;
  
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          &lt;br /&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;div id="footer"&gt;
      Copyright
  &lt;/div&gt;
  </code></pre>