title: Binding, Prefixes and generated HTML
body: <p>MVC newbie question re binders. Supposing I have two strongly typed partial actions that happen to have a model attributes with the same name, and are rendered in the same containing page i.e.:</p>
  
  <pre><code>Class Friend {string Name {get; set ;} DateTime DOB {get; set ;}}
  Class Foe {string Name {get; set ;} string ReasonForDislike {get; set ;}}
  </code></pre>
  
  <p>Both partials will have a line:</p>
  
  <pre><code>&lt;%= Html.TextBoxFor(model =&gt; model.Name) %&gt;
  </code></pre>
  
  <p>And associated controller actions:</p>
  
  <pre><code>public ActionResult SaveFriend(Friend friend)
  public ActionResult SaveFoe(Foe foe)
  </code></pre>
  
  <p>My problem is that both will render  on my containing page with the same id (of course, bad for lots of reasons). I’m aware of the [Bind] attribute that allows me add a prefix, resulting in code:</p>
  
  <pre><code>public ActionResult SaveFriend([Bind(Prefix = “friend”)] Friend friend)
  &lt;%= Html.TextBox("friend.Name", Model. Name) %&gt; //Boo, no TextBoxFor :(
  </code></pre>
  
  <p>But this still doesn’t cut it. I can just about tolerate the loss of the strongly typed TextBoxFor helpers but I’ve yet to get clientside validation to work with prefixes:
  I’ve tried:</p>
  
  <pre><code>&lt;%= Html.ValidationMessage("friend.Name") %&gt;
  </code></pre>
  
  <p>...and every other variant I can think of.</p>
  
  <p>I seem to need the model to be aware of the prefix in both directions but bind only applies when mapping the inbound request. It seems (to me) a common scenario but I’m struggling to find examples out there. What am I missing!</p>
  
  <p>Thanks in advance.</p>