title: Is there an MVC Helper Method that can be used to get the name of a form element?
body: <p>With ASP.net MVC I have a Model like so:</p>
  
  <pre><code>public class Project {
      public string ProjectName { get; set; }
      // SNIP ...
  }
  </code></pre>
  
  <p>My View contains:</p>
  
  <pre><code>@model Project
  
  @Html.TextBoxFor(m =&gt; m.ProjectName)
  </code></pre>
  
  <p>I would like to write some javascript that references the textbox:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $('#ProjectName').someMethod();
  &lt;/script&gt;
  </code></pre>
  
  <p>I don't want to hard code ProjectName in there. Ideally, I would like to use a helper method to get what the name is, just in case I refactor and rename the property:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $('#@Html.NameFor(m =&gt; m.ProjectName)').someMethod();
  &lt;/script&gt;
  </code></pre>
  
  <p>Is there something like this that I can use? I don't want to use a CSS class to trigger this, because I want to put this in an Editor Template and I don't want the code to execute for every instance of the class for every text box. I want it to execute for the one element.</p>