Browse files

Generate code for model properties in ASP.NET MVC Create view T4 temp…

…lates.
  • Loading branch information...
1 parent 0dac5a1 commit c0c385cc5467ae075f626b4e9b88374f578a906f @mrward mrward committed Nov 26, 2011
View
144 ...ndings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/AspxCSharp/Create.cs
@@ -10,6 +10,8 @@
namespace ICSharpCode.AspNet.Mvc.AspxCSharp {
using ICSharpCode.AspNet.Mvc;
+ using System.Collections.Generic;
+ using System.Reflection;
using System;
@@ -18,12 +20,17 @@ public partial class Create : CreateBase {
private global::Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost hostValue;
- #line 57 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 69 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
MvcTextTemplateHost MvcHost {
get { return (MvcTextTemplateHost)Host; }
}
+ public class ModelProperty
+ {
+ public string Name { get; set; }
+ }
+
public string GetViewPageType()
{
string viewDataTypeName = MvcHost.ViewDataTypeName;
@@ -32,6 +39,20 @@ public string GetViewPageType()
}
return String.Empty;
}
+
+ public IEnumerable<ModelProperty> GetModelProperties()
+ {
+ var properties = new List<ModelProperty>();
+ foreach (PropertyInfo propertyInfo in MvcHost.GetViewDataTypeProperties()) {
+ properties.Add(CreateModelProperty(propertyInfo));
+ }
+ return properties;
+ }
+
+ ModelProperty CreateModelProperty(PropertyInfo propertyInfo)
+ {
+ return new ModelProperty() { Name = propertyInfo.Name };
+ }
#line default
#line hidden
@@ -49,92 +70,92 @@ public string GetViewPageType()
public virtual string TransformText() {
this.GenerationEnvironment = null;
- #line 3 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 5 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
if (MvcHost.IsPartialView) {
#line default
#line hidden
- #line 4 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("<%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl");
#line default
#line hidden
- #line 4 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( GetViewPageType() ));
#line default
#line hidden
- #line 4 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("\" %>\r\n\r\n");
#line default
#line hidden
- #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 8 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
} else if (MvcHost.IsContentPage) {
#line default
#line hidden
- #line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 9 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("<%@ Page Language=\"C#\" MasterPageFile=\"");
#line default
#line hidden
- #line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 9 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.MasterPageFile ));
#line default
#line hidden
- #line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 9 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("\" Inherits=\"System.Web.Mvc.ViewPage");
#line default
#line hidden
- #line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 9 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( GetViewPageType() ));
#line default
#line hidden
- #line 7 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 9 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("\" %>\r\n\r\n<asp:Content ID=\"Content1\" ContentPlaceHolderID=\"Title\" runat=\"server\">\r\n" +
"");
#line default
#line hidden
- #line 10 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 12 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
- #line 10 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 12 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("\r\n</asp:Content>\r\n\r\n<asp:Content ID=\"Content2\" ContentPlaceHolderID=\"");
#line default
#line hidden
- #line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.PrimaryContentPlaceHolderID ));
#line default
#line hidden
- #line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("\" runat=\"server\">\r\n");
#line default
#line hidden
- #line 14 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 16 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
PushIndent("\t");
} else {
@@ -143,37 +164,37 @@ public string GetViewPageType()
#line default
#line hidden
- #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 20 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("<%@ Page Language=\"C#\" Inherits=\"System.Web.Mvc.ViewPage");
#line default
#line hidden
- #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 20 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( GetViewPageType() ));
#line default
#line hidden
- #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 20 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("\" %>\r\n\r\n<!DOCTYPE html>\r\n<html>\r\n\t<head runat=\"server\">\r\n\t\t<title>");
#line default
#line hidden
- #line 23 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 25 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
- #line 23 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 25 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("</title>\r\n\t</head>\r\n\t<body>\r\n");
#line default
#line hidden
- #line 26 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 28 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
PushIndent("\t\t");
}
@@ -182,27 +203,88 @@ public string GetViewPageType()
#line default
#line hidden
- #line 30 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 32 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("<% using (Html.BeginForm()) { %>\r\n\t<%: Html.ValidationSummary(true) %>\r\n\t<fieldse" +
"t>\r\n\t\t<legend>");
#line default
#line hidden
- #line 33 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 35 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewDataType.Name ));
#line default
#line hidden
- #line 33 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
- this.Write("</legend>\r\n\t\t\r\n\t\t<p>\r\n\t\t\t<input type=\"submit\" value=\"Create\"/>\r\n\t\t</p>\r\n\t</fields" +
- "et>\r\n<% } %>\r\n<div>\r\n\t<%: Html.ActionLink(\"Back\", \"Index\") %>\r\n</div>\r\n");
+ #line 35 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write("</legend>\r\n\t\t\r\n");
+
+ #line default
+ #line hidden
+
+ #line 37 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ foreach (var modelProperty in GetModelProperties()) {
+
+ #line default
+ #line hidden
+
+ #line 38 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write("\t\t<div class=\"editor-label\">\r\n\t\t\t<%: Html.LabelFor(model => model.");
+
+ #line default
+ #line hidden
+
+ #line 39 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
+
+ #line default
+ #line hidden
+
+ #line 39 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write(") %>\r\n\t\t</div>\r\n\t\t<div class=\"editor-field\">\r\n\t\t\t<%: Html.EditorFor(model => mode" +
+ "l.");
+
+ #line default
+ #line hidden
+
+ #line 42 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
+
+ #line default
+ #line hidden
+
+ #line 42 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write(") %>\r\n\t\t\t<%: Html.ValidationMessageFor(model => model.");
+
+ #line default
+ #line hidden
+
+ #line 43 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
#line default
#line hidden
#line 43 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write(") %>\r\n\t\t</div>\r\n\t\t\r\n");
+
+ #line default
+ #line hidden
+
+ #line 46 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ }
+
+ #line default
+ #line hidden
+
+ #line 47 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ this.Write("\t\t<p>\r\n\t\t\t<input type=\"submit\" value=\"Create\"/>\r\n\t\t</p>\r\n\t</fieldset>\r\n<% } %>\r\n<" +
+ "div>\r\n\t<%: Html.ActionLink(\"Back\", \"Index\") %>\r\n</div>\r\n");
+
+ #line default
+ #line hidden
+
+ #line 55 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
if (MvcHost.IsPartialView) {
// Do nothing.
@@ -213,13 +295,13 @@ public string GetViewPageType()
#line default
#line hidden
- #line 49 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 61 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("</asp:Content>\r\n");
#line default
#line hidden
- #line 50 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 62 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
} else {
PopIndent();
@@ -228,13 +310,13 @@ public string GetViewPageType()
#line default
#line hidden
- #line 54 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 66 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
this.Write("\t</body>\r\n</html>\r\n");
#line default
#line hidden
- #line 56 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
+ #line 68 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Create.tt"
}
#line default
View
31 ...ndings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/AspxCSharp/Create.tt
@@ -1,5 +1,7 @@
<#@ template language="C#" HostSpecific="true" #>
<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
+<#@ import namespace="System.Collections.Generic"#>
+<#@ import namespace="System.Reflection"#>
<# if (MvcHost.IsPartialView) { #>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<#= GetViewPageType() #>" %>
@@ -32,6 +34,16 @@
<fieldset>
<legend><#= MvcHost.ViewDataType.Name #></legend>
+<# foreach (var modelProperty in GetModelProperties()) { #>
+ <div class="editor-label">
+ <%: Html.LabelFor(model => model.<#= modelProperty.Name #>) %>
+ </div>
+ <div class="editor-field">
+ <%: Html.EditorFor(model => model.<#= modelProperty.Name #>) %>
+ <%: Html.ValidationMessageFor(model => model.<#= modelProperty.Name #>) %>
+ </div>
+
+<# } #>
<p>
<input type="submit" value="Create"/>
</p>
@@ -59,6 +71,11 @@
get { return (MvcTextTemplateHost)Host; }
}
+ public class ModelProperty
+ {
+ public string Name { get; set; }
+ }
+
public string GetViewPageType()
{
string viewDataTypeName = MvcHost.ViewDataTypeName;
@@ -67,4 +84,18 @@
}
return String.Empty;
}
+
+ public IEnumerable<ModelProperty> GetModelProperties()
+ {
+ var properties = new List<ModelProperty>();
+ foreach (PropertyInfo propertyInfo in MvcHost.GetViewDataTypeProperties()) {
+ properties.Add(CreateModelProperty(propertyInfo));
+ }
+ return properties;
+ }
+
+ ModelProperty CreateModelProperty(PropertyInfo propertyInfo)
+ {
+ return new ModelProperty() { Name = propertyInfo.Name };
+ }
#>
View
127 ...ndBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Create.cs
@@ -10,6 +10,8 @@
namespace ICSharpCode.AspNet.Mvc.CSHtml {
using ICSharpCode.AspNet.Mvc;
+ using System.Collections.Generic;
+ using System.Reflection;
using System;
@@ -18,12 +20,17 @@ public partial class Create : CreateBase {
private global::Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost hostValue;
- #line 53 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 65 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
MvcTextTemplateHost MvcHost {
get { return (MvcTextTemplateHost)Host; }
}
+ public class ModelProperty
+ {
+ public string Name { get; set; }
+ }
+
public string GetModelDirective()
{
string viewDataTypeName = MvcHost.ViewDataTypeName;
@@ -32,6 +39,20 @@ public string GetModelDirective()
}
return String.Empty;
}
+
+ public IEnumerable<ModelProperty> GetModelProperties()
+ {
+ var properties = new List<ModelProperty>();
+ foreach (PropertyInfo propertyInfo in MvcHost.GetViewDataTypeProperties()) {
+ properties.Add(CreateModelProperty(propertyInfo));
+ }
+ return properties;
+ }
+
+ ModelProperty CreateModelProperty(PropertyInfo propertyInfo)
+ {
+ return new ModelProperty() { Name = propertyInfo.Name };
+ }
#line default
#line hidden
@@ -49,19 +70,19 @@ public string GetModelDirective()
public virtual string TransformText() {
this.GenerationEnvironment = null;
- #line 4 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( GetModelDirective() ));
#line default
#line hidden
- #line 4 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("\r\n\r\n");
#line default
#line hidden
- #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 8 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
if (MvcHost.IsPartialView) {
// Do nothing.
@@ -71,75 +92,75 @@ public string GetModelDirective()
#line default
#line hidden
- #line 11 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("@{\r\n\tViewBag.Title = \"");
#line default
#line hidden
- #line 12 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 14 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
- #line 12 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 14 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("\";\r\n\tLayout = \"");
#line default
#line hidden
- #line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.MasterPageFile ));
#line default
#line hidden
- #line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("\";\r\n}\r\n\r\n<h2>");
#line default
#line hidden
- #line 16 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
- #line 16 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("</h2>\r\n\r\n");
#line default
#line hidden
- #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 20 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
} else {
#line default
#line hidden
- #line 21 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 23 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("<!DOCTYPE html>\r\n<html>\r\n\t<head runat=\"server\">\r\n\t\t<title>");
#line default
#line hidden
- #line 24 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 26 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewName ));
#line default
#line hidden
- #line 24 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 26 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("</title>\r\n\t</head>\r\n\t<body>\r\n");
#line default
#line hidden
- #line 27 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 29 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
PushIndent("\t\t");
}
@@ -148,27 +169,87 @@ public string GetModelDirective()
#line default
#line hidden
- #line 31 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 33 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("@using (Html.BeginForm()) {\r\n\t@Html.ValidationSummary(true)\r\n\t<fieldset>\r\n\t\t<lege" +
"nd>");
#line default
#line hidden
- #line 34 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 36 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewDataType.Name ));
#line default
#line hidden
- #line 34 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
- this.Write("</legend>\r\n\t\t\r\n\t\t<p>\r\n\t\t\t<input type=\"submit\" value=\"Create\"/>\r\n\t\t</p>\r\n\t</fields" +
- "et>\r\n}\r\n<div>\r\n\t@Html.ActionLink(\"Back\", \"Index\")\r\n</div>\r\n");
+ #line 36 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write("</legend>\r\n\t\t\r\n");
+
+ #line default
+ #line hidden
+
+ #line 38 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ foreach (var modelProperty in GetModelProperties()) {
+
+ #line default
+ #line hidden
+
+ #line 39 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write("\t\t<div class=\"editor-label\">\r\n\t\t\t@Html.LabelFor(model => model.");
+
+ #line default
+ #line hidden
+
+ #line 40 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
+
+ #line default
+ #line hidden
+
+ #line 40 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write(")\r\n\t\t</div>\r\n\t\t<div class=\"editor-field\">\r\n\t\t\t@Html.EditorFor(model => model.");
+
+ #line default
+ #line hidden
+
+ #line 43 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
+
+ #line default
+ #line hidden
+
+ #line 43 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write(")\r\n\t\t\t@Html.ValidationMessageFor(model => model.");
+
+ #line default
+ #line hidden
+
+ #line 44 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
#line default
#line hidden
#line 44 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write(")\r\n\t\t</div>\r\n\t\t\r\n");
+
+ #line default
+ #line hidden
+
+ #line 47 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ }
+
+ #line default
+ #line hidden
+
+ #line 48 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ this.Write("\t\t<p>\r\n\t\t\t<input type=\"submit\" value=\"Create\"/>\r\n\t\t</p>\r\n\t</fieldset>\r\n}\r\n<div>\r\n" +
+ "\t@Html.ActionLink(\"Back\", \"Index\")\r\n</div>\r\n");
+
+ #line default
+ #line hidden
+
+ #line 56 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
if (MvcHost.IsPartialView) {
// Do nothing.
@@ -179,13 +260,13 @@ public string GetModelDirective()
#line default
#line hidden
- #line 50 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 62 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
this.Write("\t</body>\r\n</html>\r\n");
#line default
#line hidden
- #line 52 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
+ #line 64 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Create.tt"
}
#line default
View
31 ...ndBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Create.tt
@@ -1,5 +1,7 @@
<#@ template language="C#" HostSpecific="true" #>
<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
+<#@ import namespace="System.Collections.Generic" #>
+<#@ import namespace="System.Reflection" #>
<#@ output extension=".cshtml" #>
<#= GetModelDirective() #>
@@ -33,6 +35,16 @@
<fieldset>
<legend><#= MvcHost.ViewDataType.Name #></legend>
+<# foreach (var modelProperty in GetModelProperties()) { #>
+ <div class="editor-label">
+ @Html.LabelFor(model => model.<#= modelProperty.Name #>)
+ </div>
+ <div class="editor-field">
+ @Html.EditorFor(model => model.<#= modelProperty.Name #>)
+ @Html.ValidationMessageFor(model => model.<#= modelProperty.Name #>)
+ </div>
+
+<# } #>
<p>
<input type="submit" value="Create"/>
</p>
@@ -55,6 +67,11 @@
get { return (MvcTextTemplateHost)Host; }
}
+ public class ModelProperty
+ {
+ public string Name { get; set; }
+ }
+
public string GetModelDirective()
{
string viewDataTypeName = MvcHost.ViewDataTypeName;
@@ -63,4 +80,18 @@
}
return String.Empty;
}
+
+ public IEnumerable<ModelProperty> GetModelProperties()
+ {
+ var properties = new List<ModelProperty>();
+ foreach (PropertyInfo propertyInfo in MvcHost.GetViewDataTypeProperties()) {
+ properties.Add(CreateModelProperty(propertyInfo));
+ }
+ return properties;
+ }
+
+ ModelProperty CreateModelProperty(PropertyInfo propertyInfo)
+ {
+ return new ModelProperty() { Name = propertyInfo.Name };
+ }
#>
View
28 ...Net.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/AspxVisualBasic/Create.tt
@@ -1,6 +1,8 @@
<#@ template language="VB" HostSpecific="true" #>
<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
<#@ import namespace="Microsoft.VisualBasic.Constants" #>
+<#@ import namespace="System.Collections.Generic" #>
+<#@ import namespace="System.Reflection" #>
<# If MvcHost.IsPartialView Then #>
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl<#= GetViewPageType() #>" %>
@@ -33,6 +35,16 @@
<fieldset>
<legend><#= MvcHost.ViewDataType.Name #></legend>
+<# For Each modelProperty As ModelProperty in GetModelProperties() #>
+ <div class="editor-label">
+ <%: Html.LabelFor(Function(model) model.<#= modelProperty.Name #>) %>
+ </div>
+ <div class="editor-field">
+ <%: Html.EditorFor(Function(model) model.<#= modelProperty.Name #>) %>
+ <%: Html.ValidationMessageFor(Function(model) model.<#= modelProperty.Name #>) %>
+ </div>
+
+<# Next #>
<p>
<input type="submit" value="Create"/>
</p>
@@ -62,11 +74,27 @@
End Get
End Property
+ Public Class ModelProperty
+ Public Property Name As String
+ End Class
+
Public Function GetViewPageType() As String
Dim viewDataTypeName As String = MvcHost.ViewDataTypeName
If Not String.IsNullOrEmpty(viewDataTypeName) Then
Return String.Format("(Of {0})", viewDataTypeName)
End If
Return String.Empty
End Function
+
+ Public Function GetModelProperties() As IEnumerable(Of ModelProperty)
+ Dim properties = New List(Of ModelProperty)()
+ For Each propertyInfo As PropertyInfo In MvcHost.GetViewDataTypeProperties()
+ properties.Add(CreateModelProperty(propertyInfo))
+ Next
+ Return properties
+ End Function
+
+ Function CreateModelProperty(ByVal propertyInfo As PropertyInfo) As ModelProperty
+ Return New ModelProperty() With { .Name = propertyInfo.Name }
+ End Function
#>
View
28 ...dings/AspNet.Mvc/Project/ItemTemplates/VisualBasic/CodeTemplates/AddView/VBHTML/Create.tt
@@ -1,6 +1,8 @@
<#@ template language="VB" HostSpecific="true" #>
<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
<#@ import namespace="Microsoft.VisualBasic.Constants" #>
+<#@ import namespace="System.Collections.Generic" #>
+<#@ import namespace="System.Reflection" #>
<#@ output extension=".vbhtml" #>
<#= GetModelDirective() #>
@@ -34,6 +36,16 @@ End Code
@<fieldset>
<legend><#= MvcHost.ViewDataType.Name #></legend>
+<# For Each modelProperty As ModelProperty in GetModelProperties() #>
+ <div class="editor-label">
+ @Html.LabelFor(Function(model) model.<#= modelProperty.Name #>)
+ </div>
+ <div class="editor-field">
+ @Html.EditorFor(Function(model) model.<#= modelProperty.Name #>)
+ @Html.ValidationMessageFor(Function(model) model.<#= modelProperty.Name #>)
+ </div>
+
+<# Next #>
<p>
<input type="submit" value="Create"/>
</p>
@@ -58,11 +70,27 @@ End Using
End Get
End Property
+ Public Class ModelProperty
+ Public Property Name As String
+ End Class
+
Function GetModelDirective() As String
Dim viewDataTypeName As String = MvcHost.ViewDataTypeName
If Not String.IsNullOrEmpty(viewDataTypeName) Then
Return String.Format("@ModelType {0}", viewDataTypeName)
End If
Return String.Empty
End Function
+
+ Public Function GetModelProperties() As IEnumerable(Of ModelProperty)
+ Dim properties = New List(Of ModelProperty)()
+ For Each propertyInfo As PropertyInfo In MvcHost.GetViewDataTypeProperties()
+ properties.Add(CreateModelProperty(propertyInfo))
+ Next
+ Return properties
+ End Function
+
+ Function CreateModelProperty(ByVal propertyInfo As PropertyInfo) As ModelProperty
+ Return New ModelProperty() With { .Name = propertyInfo.Name }
+ End Function
#>
View
5 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcTextTemplateHost.cs
@@ -67,6 +67,11 @@ string UseEmptyStringIfNull(string value)
set { viewDataTypeAssemblyLocation = UseEmptyStringIfNull(value); }
}
+ public PropertyInfo[] GetViewDataTypeProperties()
+ {
+ return ViewDataType.GetProperties();
+ }
+
public Type ViewDataType {
get {
if (viewDataType == null) {
View
1 src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj
@@ -92,6 +92,7 @@
<Compile Include="Src\CodeTemplates\AspxCSharpEmptyViewTemplateTests.cs" />
<Compile Include="Src\CodeTemplates\AspxCSharpListViewTemplateTests.cs" />
<Compile Include="Src\CodeTemplates\Models\ModelWithNoProperties.cs" />
+ <Compile Include="Src\CodeTemplates\Models\ModelWithOneProperty.cs" />
<Compile Include="Src\CodeTemplates\RazorCSharpCreateViewTemplateTests.cs" />
<Compile Include="Src\CodeTemplates\RazorCSharpDeleteViewTemplateTests.cs" />
<Compile Include="Src\CodeTemplates\RazorCSharpDetailsViewTemplateTests.cs" />
View
64 ...ns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/AspxCSharpCreateViewTemplateTests.cs
@@ -2,6 +2,9 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using System.Collections.Generic;
+using System.Linq;
+
using AspNet.Mvc.Tests.CodeTemplates.Models;
using AspNet.Mvc.Tests.Helpers;
using ICSharpCode.AspNet.Mvc.AspxCSharp;
@@ -22,6 +25,16 @@ void CreateViewTemplatePreprocessor()
templatePreprocessor.Host = mvcHost;
}
+ IEnumerable<Create.ModelProperty> GetModelProperties()
+ {
+ return templatePreprocessor.GetModelProperties();
+ }
+
+ Create.ModelProperty GetFirstModelProperty()
+ {
+ return GetModelProperties().First();
+ }
+
[Test]
public void GetViewPageType_HostViewDataTypeNameIsMyAppMyModel_ReturnsMyAppMyModelSurroundedByAngleBrackets()
{
@@ -165,5 +178,56 @@ public void TransformText_ModelHasNoPropertiesAndIsPartialView_ReturnsControlWit
";
Assert.AreEqual(expectedOutput, output);
}
+
+ [Test]
+ public void GetModelProperties_ModelHasOnePropertyCalledName_ReturnsModelPropertyCalledName()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.ViewDataType = typeof(ModelWithOneProperty);
+
+ Create.ModelProperty modelProperty = GetFirstModelProperty();
+
+ Assert.AreEqual("Name", modelProperty.Name);
+ }
+
+ [Test]
+ public void TransformText_ModelHasOnePropertyAndIsPartialView_ReturnsControlWithFormAndHtmlEditorForProperty()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.IsPartialView = true;
+ Type modelType = typeof(ModelWithOneProperty);
+ mvcHost.ViewDataType = modelType;
+ mvcHost.ViewDataTypeName = modelType.FullName;
+ mvcHost.ViewName = "MyView";
+
+ string output = templatePreprocessor.TransformText();
+
+ string expectedOutput =
+@"<%@ Control Language=""C#"" Inherits=""System.Web.Mvc.ViewUserControl<AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithOneProperty>"" %>
+
+<% using (Html.BeginForm()) { %>
+ <%: Html.ValidationSummary(true) %>
+ <fieldset>
+ <legend>ModelWithOneProperty</legend>
+
+ <div class=""editor-label"">
+ <%: Html.LabelFor(model => model.Name) %>
+ </div>
+ <div class=""editor-field"">
+ <%: Html.EditorFor(model => model.Name) %>
+ <%: Html.ValidationMessageFor(model => model.Name) %>
+ </div>
+
+ <p>
+ <input type=""submit"" value=""Create""/>
+ </p>
+ </fieldset>
+<% } %>
+<div>
+ <%: Html.ActionLink(""Back"", ""Index"") %>
+</div>
+";
+ Assert.AreEqual(expectedOutput, output);
+ }
}
}
View
12 src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/Models/ModelWithOneProperty.cs
@@ -0,0 +1,12 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+
+namespace AspNet.Mvc.Tests.CodeTemplates.Models
+{
+ public class ModelWithOneProperty
+ {
+ public string Name { get; set; }
+ }
+}
View
64 ...s/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpCreateViewTemplateTests.cs
@@ -2,6 +2,9 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using System.Collections.Generic;
+using System.Linq;
+
using AspNet.Mvc.Tests.CodeTemplates.Models;
using AspNet.Mvc.Tests.Helpers;
using ICSharpCode.AspNet.Mvc.CSHtml;
@@ -22,6 +25,16 @@ void CreateViewTemplatePreprocessor()
templatePreprocessor.Host = mvcHost;
}
+ IEnumerable<Create.ModelProperty> GetModelProperties()
+ {
+ return templatePreprocessor.GetModelProperties();
+ }
+
+ Create.ModelProperty GetFirstModelProperty()
+ {
+ return GetModelProperties().First();
+ }
+
[Test]
public void GetModelDirective_HostViewDataTypeNameIsMyAppMyModel_ReturnsRazorModelFollowedByMyAppMyModel()
{
@@ -166,5 +179,56 @@ public void TransformText_ModelHasNoPropertiesAndIsContentPage_ReturnsContentPag
";
Assert.AreEqual(expectedOutput, output);
}
+
+ [Test]
+ public void GetModelProperties_ModelHasOnePropertyCalledName_ReturnsModelPropertyCalledName()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.ViewDataType = typeof(ModelWithOneProperty);
+
+ Create.ModelProperty modelProperty = GetFirstModelProperty();
+
+ Assert.AreEqual("Name", modelProperty.Name);
+ }
+
+ [Test]
+ public void TransformText_ModelHasOnePropertyAndIsPartialView_ReturnsControlWithHtmlEditorsForModelProperties()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.IsPartialView = true;
+ Type modelType = typeof(ModelWithOneProperty);
+ mvcHost.ViewDataType = modelType;
+ mvcHost.ViewDataTypeName = modelType.FullName;
+ mvcHost.ViewName = "MyView";
+
+ string output = templatePreprocessor.TransformText();
+
+ string expectedOutput =
+@"@model AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithOneProperty
+
+@using (Html.BeginForm()) {
+ @Html.ValidationSummary(true)
+ <fieldset>
+ <legend>ModelWithOneProperty</legend>
+
+ <div class=""editor-label"">
+ @Html.LabelFor(model => model.Name)
+ </div>
+ <div class=""editor-field"">
+ @Html.EditorFor(model => model.Name)
+ @Html.ValidationMessageFor(model => model.Name)
+ </div>
+
+ <p>
+ <input type=""submit"" value=""Create""/>
+ </p>
+ </fieldset>
+}
+<div>
+ @Html.ActionLink(""Back"", ""Index"")
+</div>
+";
+ Assert.AreEqual(expectedOutput, output);
+ }
}
}
View
15 src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/MvcTextTemplateHostTests.cs
@@ -2,6 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using System.Linq;
+using System.Reflection;
+
+using AspNet.Mvc.Tests.CodeTemplates.Models;
using AspNet.Mvc.Tests.Helpers;
using ICSharpCode.AspNet.Mvc;
using NUnit.Framework;
@@ -172,5 +176,16 @@ public void ViewDataType_CalledTwice_AssemblyLoadedOnlyOnce()
Assert.IsNull(host.FileNamePassedToLoadAssemblyFrom);
}
+
+ [Test]
+ public void GetViewDataTypeProperties_ViewDataTypeIsModelWithOnePropertyCalledName_ReturnsOnePropertyCalledName()
+ {
+ CreateHost();
+ host.ViewDataType = typeof(ModelWithOneProperty);
+
+ PropertyInfo propertyInfo = host.GetViewDataTypeProperties().First();
+
+ Assert.AreEqual("Name", propertyInfo.Name);
+ }
}
}

0 comments on commit c0c385c

Please sign in to comment.