Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have not tried preview 1 yet but they did what you are asking for in this channel9 video:</p> <p><a href="http://channel9.msdn.com/posts/Glucose/Hanselminutes-on-9-ASPNET-MVC-2-Preview-1-with-Phil-Haack-and-Virtual-Scott/" rel="nofollow noreferrer">http://channel9.msdn.com/posts/Glucose/Hanselminutes-on-9-ASPNET-MVC-2-Preview-1-with-Phil-Haack-and-Virtual-Scott/</a></p> <p>They do both DisplayFor and EditorFor, starts around 2 minutes.</p> <p>--Edit--</p> <p>For value type i.e. int I was able to get it to work in the same way.</p> <p>Create a model to pass to my view:</p> <pre><code>public class HomeController : Controller { public ActionResult Index() { HomeModel model = new HomeModel(); model.message = "Welcome to ASP.NET MVC!"; model.number = 526562262; model.Date = DateTime.Now; return View(model); } } public class HomeModel { public string message { get; set; } public int number { get; set; } public DateTime Date { get; set; } } </code></pre> <p>Link view to the model using the new template logic:</p> <pre><code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;HomeModel&gt;" %&gt; &lt;asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;p&gt; &lt;% Html.EditorFor(c =&gt; c.message); %&gt; &lt;/p&gt; &lt;p&gt; &lt;% Html.EditorFor(c =&gt; c.number); %&gt; &lt;/p&gt; &lt;p&gt; &lt;% Html.EditorFor(c =&gt; c.Date); %&gt; &lt;/p&gt; </code></pre> <p></p> <p>Then create a template for each of the types e.g. Int32:</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %&gt; Editor For My Int32: &lt;%= Html.TextBox("abc", Model.ToString())%&gt; </code></pre> <p>I put this in Views\Shared\EditorTemplates\Int32.ascx</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload