title: Adding value from html page on database
body: <p>I use Microsoft Visual Studio and Microsoft sql server 2008. I create web site and I want to add text value which user enter information on sql table. I use Nhibarnate and FluentNhibernate. But my code can not add value. I create map , entity and how can I add value from web page text. What can I do for this problem?</p>
  
  <p><strong>table</strong></p>
  
  <pre><code>  |Address table|
      --------------
      |AddressId     | int
      ------------------------
      |FullName      | varchar
      ------------------------
      |AddressLine1  | varchar
      ------------------------ 
      |AddressLine2  | varchar 
      ------------------------
      |city          | varchar
      ------------------------
      |State         | varchar
      ------------------------
      |zip           | varchar
      ------------------------
      |country       | varchar
      ------------------------
  </code></pre>
  
  <p>FluentlyConfig.cs</p>
  
  <pre><code>namespace Deneme.Config
  {
      public class FluentlyConfig
      {
          private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
          private ISessionFactory SessionFactory { get; set; }
  
          private FluentlyConfig()
          {
              SessionFactory = CreateSessionFactory();
          }
  
          public static FluentlyConfig Instance
          {
              get
              {
                  return FluentNhibernateConfigFactory.instance;
              }
          }
  
          public class FluentNhibernateConfigFactory
          {
              static FluentNhibernateConfigFactory() { }
              internal static readonly FluentlyConfig instance = new FluentlyConfig();
          }
  
          public ISessionFactory CreateSessionFactory()
          {
              try
              {
                  if (this.SessionFactory == null)
                  {
                      return Fluently.Configure()
                      .Database(
                      MsSqlConfiguration
                      .MsSql2008
                      .ConnectionString(c =&gt; c
                      .FromConnectionStringWithKey("DB"))
                      .DefaultSchema("dbo")
                      )
                      .Mappings(m =&gt;
                      {
                          m.FluentMappings
                          .AddFromAssemblyOf&lt;Address&gt;()
                         .Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never());
                      })
                      .BuildSessionFactory();
                  }
                  else { return SessionFactory; }
              }
              catch (Exception ex)
              {
                  logger.Fatal("Bağlantı Oluşturulamadı", ex);
                  return null;
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  
  namespace Deneme.Controllers
  {
      public class Default1Controller : Controller
      {
          //
          // GET: /Default1/
  
          public ActionResult Index()
          { 
              return View();
          }
          public JsonResult deneme( String AddressId, String FullName, String AddressLine1 ,String  AddressLine2 ,String City ,String State, String Zip ,String Country )
          {
          return new JsonResult();           
          }
  
      }
  }
  </code></pre>
  
  <p><strong>Entities</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace Deneme.Entities
  {
      public class Address
      {
      public virtual int AddressId {get; set;}
      public virtual string FullName {get; set;}
      public virtual string AddressLine1 {get; set;}
      public virtual string AddressLine2 {get; set;}
      public virtual string City {get; set;}
      public virtual string State {get; set;}
      public virtual string Zip {get; set;}
      public virtual string Country {get; set;}
  
  //AddressId FullName AddressLine1 AddressLine2 City State Zip Country
      }
  }
  </code></pre>
  
  <p><strong>Mapping</strong></p>
  
  <pre><code>using Deneme.Entities;
  using FluentNHibernate.Mapping;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Deneme.Mapping
  {
      public class AddressMap : ClassMap&lt;Address&gt;
      {
          public AddressMap()
          {
              Table("Address");
              Id(x =&gt; x.AddressId).Column("Id").GeneratedBy.Identity();
              Map(x =&gt; x.FullName).Column("Fullname");
              Map(x =&gt; x.AddressLine1).Column("AddressLine1");
              Map(x =&gt; x.AddressLine2).Column("AddressLine2");
              Map(x =&gt; x.City).Column("City");
              Map(x =&gt; x.State).Column("State");
              Map(x =&gt; x.Zip).Column("Zip");
              Map(x =&gt; x.Country).Column("Country");
          }  
      }
  }
  </code></pre>
  
  <p><strong>Index.cshtml text part and js part. I want to send value after click button</strong></p>
  
  <p><strong>button</strong></p>
  
  <pre><code> &lt;p&gt;&lt;a href="button1" class="btn btn-primary btn-large"&gt;Send &amp;raquo;&lt;/a&gt;&lt;/p&gt;
  </code></pre>
  
  <p><strong>Address Form Part</strong></p>
  
  <p><h2>Address</h2></p>
  
  <pre><code>        &lt;!-- full-name input--&gt;
          &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;Full Name&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;input id="full-name" name="full-name" type="text" placeholder="full name"
                  class="input-xlarge"&gt;
                  &lt;p class="help-block"&gt;&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- address-line1 input--&gt;
          &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;Address Line 1&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;input id="address-line1" name="address-line1" type="text" placeholder="address line 1"
                  class="input-xlarge"&gt;
                  &lt;p class="help-block"&gt;Street address, P.O. box, company name, c/o&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- address-line2 input--&gt;
          &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;Address Line 2&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;input id="address-line2" name="address-line2" type="text" placeholder="address line 2"
                  class="input-xlarge"&gt;
                  &lt;p class="help-block"&gt;Apartment, suite , unit, building, floor, etc.&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- city input--&gt;
          &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;City / Town&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;input id="city" name="city" type="text" placeholder="city" class="input-xlarge"&gt;
                  &lt;p class="help-block"&gt;&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- region input--&gt;
          &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;State / Province / Region&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;input id="region" name="region" type="text" placeholder="state / province / region"
                  class="input-xlarge"&gt;
                  &lt;p class="help-block"&gt;&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- postal-code input--&gt;
          &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;Zip / Postal Code&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;input id="postal-code" name="postal-code" type="text" placeholder="zip or postal code"
                  class="input-xlarge"&gt;
                  &lt;p class="help-block"&gt;&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- country select --&gt;
          &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;Country&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;select id="country" name="country" class="input-xlarge"&gt;
                      &lt;option value="" selected="selected"&gt;(please select a country)&lt;/option&gt;
                      &lt;option value="AF"&gt;Afghanistan&lt;/option&gt;
                      &lt;option value="AL"&gt;Albania&lt;/option&gt;
                      &lt;option value="DZ"&gt;Algeria&lt;/option&gt;
                      &lt;option value="AS"&gt;American Samoa&lt;/option&gt;
                      &lt;option value="AD"&gt;Andorra&lt;/option&gt;
                      &lt;option value="AO"&gt;Angola&lt;/option&gt;
                      &lt;option value="AI"&gt;Anguilla&lt;/option&gt;
                      &lt;option value="AQ"&gt;Antarctica&lt;/option&gt;
                      &lt;option value="AG"&gt;Antigua and Barbuda&lt;/option&gt;
                      &lt;option value="AR"&gt;Argentina&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p><strong>java script part</strong></p>
  
  <pre><code>@section jscript
  {
      &lt;script type="text/javascript"&gt;
          $("#button1").live("click", function () {
               $.ajax({
                      type: "POST",
                      url: path + "Default1/deneme",
                      contentType: "application/json;charset=utf-8",
                      data: "{FullName:\"" + $("#full-name").val() +
                           "}",
                      data: "{AddressLine1:\"" + $("#address-line1").val() +
                             "}",
                      data: "{AddressLine2:\"" + $("#address-line2").val() +
                              "}",
                      data: "{ City:\"" + $("#city").val() +
                              "}",
                      data: "{State:\"" + $("#region").val() +
                              "}",
                      data: "{Zip:\"" + $("#postal-code").val() +
                              "}",
                      data: "{Country:\"" + $("#country").val() +
                              "}",
  
                      success: function (data) {
  
  
                      },
                      error: function (xhr, ajaxOptions, thrownError) {
                          $("#button1").removeAttr("disabled");
                          alert(thrownError);
                      }
                  });
  
          });
      &lt;/script&gt;
  }
  </code></pre>
  
  <p><strong>AND the last  Web.config. I do data base and w.studio connection at this part.</strong> </p>
  
  <pre><code>  &lt;connectionStrings&gt;
      &lt;add name="DB" connectionString="server=A88;uid=ABC;pwd=123;database=DS"/&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p><strong>Action.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using Deneme.Entities;
  
  namespace Deneme
  {
      public class Actions
      {
          public bool SaveData(string AddressId, string FullName, string AddressLine1, string AddressLine2, string City, string State, string Zip, string Country)
          {
              Address adress = new Address();
  
              adress.City= City;
              adress.AddressLine1 = AddressLine1;
              adress.AddressLine2 = AddressLine2;
              adress.Country = Country;
              adress.FullName = FullName;
              adress.State = State;
              adress.Zip = Zip;
               return true;
  
          }
      }
  }
  </code></pre>