title: How to create an MVC UserControl
body: <p>I am trying to create a user control in an ASP.NET MVC project.  I basically have some formatted data that I want to put inside a repeater.  In standard ASP.NET, I would populate the control something like this:</p>
  
  <pre><code> &lt;asp:Repeater ID="MyRepeater" runat="server" 
                 DataSourceID="SQLDataSource" DataMember="DefaultView"&gt;
       &lt;ItemTemplate&gt;                             
            &lt;uc1:Control ID = "MyControl" runat="server" 
                         Field1='&lt;%#Eval("[\"Field1\"]") %&gt;' Field2='&lt;%#Eval("[\"Field2\"]") %&gt;' /&gt;                            
       &lt;/ItemTemplate&gt;
   &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>And the control would have corresponding properties in the codefile.  However, in MVC, I don’t get a codefile as standard.  I found <a href="https://stackoverflow.com/questions/680448/how-to-add-a-code-behind-page-to-a-view-or-partial-view">this</a> question that describes how to add one, but then wondered if there is a better way of doing this in MVC (I couldn’t find any decent articles that said the recommended way).</p>