title: asp.net mvc get value from Html.TextBoxFor()
body: <p>I'm new to MVC(Asp.net) as well as JavaScript. sorry for this primary question.</p>
  
  <pre><code>&lt;body&gt;
      &lt;div&gt;
      &lt;%--&lt;% Html.BeginForm(); %&gt;--%&gt;
      &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;%:Html.LabelFor(t=&gt; t.CustomerID) %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%:Html.TextBoxFor(t =&gt; t.CustomerID, new { ID = "txtCustomerID" })%&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;%:Html.LabelFor(t=&gt; t.CustomerName) %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%:Html.TextBoxFor(t =&gt; t.CustomerName, new { ID = "txtCustomerName" })%&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type="submit" value="Submit" onclick="CheckName()" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
       &lt;%--&lt;% Html.EndForm(); %&gt;--%&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I need to get <code>t.CustomerName</code> value using JavaScript. I tried as below and it gives me errors.</p>
  
  <pre><code>&lt;head runat="server"&gt;
      &lt;script type="text/javascript"&gt;
          function CheckName() {
              var value = document.getElementById('&lt;%=t.CustomerName%&gt;').value;
              alert(value);
          }
  
   function SubmitData() {
          var obj = {};
          obj.CustomerID = $("#txtCustomerID").val();
          obj.CustomerName = $("#txtCustomerName").val();
  
          $.ajax({
              url: "CreateNewRetailCustomer?jsonObject=" + JSON.stringify(obj),
              type: 'POST',
              contentType: 'application/json; charset=utf-8',
              dataType: 'json',
              success: function (result) {
                  if (result.status == "successful") {
                      document.location.href = '../';
                  }
              }
          });
      }
      &lt;/script&gt;
      &lt;title&gt;Create Wholesale Customer&lt;/title&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>i wrote my controller coding as below :</p>
  
  <pre><code>public ActionResult CreateRetailCustomer()
          {
  
              return View();
          }
  
           [HttpPost]
          public ActionResult CreateRetailCustomer(RetailCustomer retCust)
          {            
              new CustomerService.CustomerServiceClient().SaveRetailCustomer(retCust);
              return RedirectToAction("Index");
          }
  
           [HttpPost]
           public JsonResult CreateRetailCustomer(string jsonObject)
           {
               var retailCustomer = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize&lt;Models.RetailCustomer&gt;(jsonObject);
               new CustomerService.CustomerServiceClient().SaveRetailCustomer(retailCustomer);
               return Json(new { status = "successful" }, JsonRequestBehavior.AllowGet);             
           }
  
  
          [HttpGet]
          public JsonResult GetCustomerList()
          {
              var custlist = new CustomerService.CustomerServiceClient().GetCustomer().Select(m =&gt; new { CustomerId = m.CustomerId, CustomerName = m.CustomerName});
              return Json(custlist, JsonRequestBehavior.AllowGet);
          }
  </code></pre>
  
  <p><strong>error:</strong></p>
  
  <blockquote>
    <p>An error occurred during the compilation of a resource required to
    service this request. Please review the following specific error
    details and modify your source code appropriately.</p>
  </blockquote>
  
  <p>I searched and I found similar question <a href="https://stackoverflow.com/questions/6014622/asp-net-mvc-get-value-from-html-textbox">asp.net mvc get value from Html.textbox()</a> here. but it doesn't discussed about how to get value from <code>Html.TextBoxFor</code> so how can I do this?</p>