title: Creating EditorTemplate for string properties ASP.NET MVC4
body: <p>When I'm using the Html.EditorFor helper in my form, I wish to be able to customize the look of the  tag and so I defined a EditorTemplate to be able to do just that. This is what my form looks like in my view :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@model Models.SimpleUserClass
  @{
      ViewBag.Title = "Create User";
  }
  
  &lt;div class="row"&gt;
      &lt;div class="col-lg-6" id="FromPlaceHoler"&gt;
  
          @using (Html.BeginForm("CreateUser", "Users"))
          {
  
              &lt;fieldset&gt;
                  &lt;legend&gt;Create One Way Trip&lt;/legend&gt;
  
                  &lt;div class="editor-label"&gt;
                      @Html.LabelFor(model =&gt; model.UserName)
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.UserName)
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      @Html.LabelFor(model =&gt; model.UserSurname)
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.UserSurname)
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      @Html.LabelFor(model =&gt; model.UserAge)
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.UserAge)
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      @Html.LabelFor(model =&gt; model.UserGender)
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.UserGender)
                  &lt;/div&gt;
  
                  &lt;p&gt;
                      &lt;input type="submit" value="Create" /&gt;
                  &lt;/p&gt;
              &lt;/fieldset&gt;
          }
      &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Properties like UserName and Surname are of type String, so in my Shared folder I Created the EditorTemplates folder and created a String.cshtml file to define the way a editor for a String should look like. When running a test of the form, it seems to be working well since the input fields that is generated has appearance that I specified - problem is when I submit a form using these custom input fields, mvc cannot map my form fields to my model. The reason for this is the properties that the  tag needs to support this binding to models. Here follows an example:</p>
  
  <p>Here is my code in the String.cshtml EditorTemplate :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" class="form-control"&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and when using the default EditorFor without customization it generates the following markup:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input data-val="true" data-val-required="The User Name field is required." id="UserName" name="UserName" type="text" value="" /&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>As we can see above, my code does not have the 'id' and 'name' properties that correlate to the name of my properties in my class and which is used to bind values to my class. So how to I change the code in the String.cshtml to include these properties and set their values dynamically? since it should be used for various properties in my class?</p>