值类型ASP.NET MVC 2的编辑模板,INT [英] ASP.NET MVC 2 editor template for value types, int
问题描述
我想创建一个值类型,即int类型的MVC 2的编辑模板,也没有人这样做与preVIEW 1位?
I want to create a MVC 2 editor template for a value type i.e. int , has anyone done this with the preview 1 bits?
非常感谢
推荐答案
我还没有试过preVIEW 1,但还没有他们做了什么,你在这个Channel9的视频要求:
I have not tried preview 1 yet but they did what you are asking for in this channel9 video:
<一个href=\"http://channel9.msdn.com/posts/Glucose/Hanselminutes-on-9-ASPNET-MVC-2-$p$pview-1-with-Phil-Haack-and-Virtual-Scott/\" rel=\"nofollow\">http://channel9.msdn.com/posts/Glucose/Hanselminutes-on-9-ASPNET-MVC-2-$p$pview-1-with-Phil-Haack-and-Virtual-Scott/
他们这样做DisplayFor和EditorFor都,开始2分钟左右。
They do both DisplayFor and EditorFor, starts around 2 minutes.
- 编辑 -
有关值类型即诠释我能得到它在相同的方式工作。
For value type i.e. int I was able to get it to work in the same way.
创建了一个模型来传递给我的看法:
Create a model to pass to my view:
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; }
}
使用新的模板逻辑链接视图到模型:
Link view to the model using the new template logic:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<HomeModel>" %>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<p>
<% Html.EditorFor(c => c.message); %>
</p>
<p>
<% Html.EditorFor(c => c.number); %>
</p>
<p>
<% Html.EditorFor(c => c.Date); %>
</p>
然后,对于每个类型的创建模板例如INT32:
Then create a template for each of the types e.g. Int32:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
Editor For My Int32: <%= Html.TextBox("abc", Model.ToString())%>
我把这个意见\\共享\\ EditorTemplates \\ Int32.ascx
I put this in Views\Shared\EditorTemplates\Int32.ascx
这篇关于值类型ASP.NET MVC 2的编辑模板,INT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!