Permalink
Browse files

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

…lates.
  • Loading branch information...
1 parent c0c385c commit 6ebfe59c203aced19a3384ef392639b20934ba7e @mrward mrward committed Nov 26, 2011
@@ -223,7 +223,7 @@ ModelProperty CreateModelProperty(PropertyInfo propertyInfo)
#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()) {
+ foreach (ModelProperty modelProperty in GetModelProperties()) {
#line default
#line hidden
@@ -34,7 +34,7 @@
<fieldset>
<legend><#= MvcHost.ViewDataType.Name #></legend>
-<# foreach (var modelProperty in GetModelProperties()) { #>
+<# foreach (ModelProperty modelProperty in GetModelProperties()) { #>
<div class="editor-label">
<%: Html.LabelFor(model => model.<#= modelProperty.Name #>) %>
</div>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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() #>" %>
@@ -29,6 +31,15 @@
#>
<fieldset>
<legend><#= MvcHost.ViewDataType.Name #></legend>
+<# foreach (ModelProperty modelProperty in GetModelProperties()) { #>
+
+ <div class="display-label">
+ <%: Html.LabelFor(model => model.<#= modelProperty.Name#>) %>
+ </div>
+ <div class="display-field">
+ <%: Html.DisplayFor(model => model.<#= modelProperty.Name#>) %>
+ </div>
+<# } #>
</fieldset>
<% using (Html.BeginForm()) { %>
<p>
@@ -55,6 +66,11 @@
get { return (MvcTextTemplateHost)Host; }
}
+ public class ModelProperty
+ {
+ public string Name { get; set; }
+ }
+
public string GetViewPageType()
{
string viewDataTypeName = MvcHost.ViewDataTypeName;
@@ -63,4 +79,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 };
+ }
#>
@@ -189,7 +189,7 @@ ModelProperty CreateModelProperty(PropertyInfo propertyInfo)
#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()) {
+ foreach (ModelProperty modelProperty in GetModelProperties()) {
#line default
#line hidden
@@ -35,7 +35,7 @@
<fieldset>
<legend><#= MvcHost.ViewDataType.Name #></legend>
-<# foreach (var modelProperty in GetModelProperties()) { #>
+<# foreach (ModelProperty modelProperty in GetModelProperties()) { #>
<div class="editor-label">
@Html.LabelFor(model => model.<#= modelProperty.Name #>)
</div>
@@ -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 Delete : DeleteBase {
private global::Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost hostValue;
- #line 49 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ #line 60 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 6 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 8 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 13 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 14 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 14 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 15 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 18 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 20 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
} else {
#line default
#line hidden
- #line 21 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ #line 23 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 26 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 26 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.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\Delete.tt"
+ #line 29 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
PushIndent("\t\t");
}
@@ -148,26 +169,74 @@ 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\Delete.tt"
+ #line 33 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
this.Write("<fieldset>\r\n\t<legend>");
#line default
#line hidden
- #line 32 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ #line 34 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
this.Write(this.ToStringHelper.ToStringWithCulture( MvcHost.ViewDataType.Name ));
#line default
#line hidden
- #line 32 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
- this.Write("</legend>\r\n</fieldset>\r\n@using (Html.BeginForm()) {\r\n\t<p>\r\n\t\t<input type=\"submit\"" +
- " value=\"Delete\"/> |\r\n\t\t@Html.ActionLink(\"Back\", \"Index\")\r\n\t</p>\r\n}\r\n");
+ #line 34 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ this.Write("</legend>\r\n");
+
+ #line default
+ #line hidden
+
+ #line 35 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ foreach (ModelProperty modelProperty in GetModelProperties()) {
+
+ #line default
+ #line hidden
+
+ #line 36 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ this.Write("\t\r\n\t<div class=\"display-label\">\r\n\t\t@Html.LabelFor(model => model.");
+
+ #line default
+ #line hidden
+
+ #line 38 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
+
+ #line default
+ #line hidden
+
+ #line 38 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ this.Write(")\r\n\t</div>\r\n\t<div class=\"display-field\">\r\n\t\t@Html.DisplayFor(model => model.");
+
+ #line default
+ #line hidden
+
+ #line 41 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture( modelProperty.Name ));
+
+ #line default
+ #line hidden
+
+ #line 41 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ this.Write(")\r\n\t</div>\r\n");
+
+ #line default
+ #line hidden
+
+ #line 43 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ }
+
+ #line default
+ #line hidden
+
+ #line 44 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ this.Write("</fieldset>\r\n@using (Html.BeginForm()) {\r\n\t<p>\r\n\t\t<input type=\"submit\" value=\"Del" +
+ "ete\"/> |\r\n\t\t@Html.ActionLink(\"Back\", \"Index\")\r\n\t</p>\r\n}\r\n");
#line default
#line hidden
- #line 40 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ #line 51 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
if (MvcHost.IsPartialView) {
// Do nothing.
@@ -178,13 +247,13 @@ public string GetModelDirective()
#line default
#line hidden
- #line 46 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ #line 57 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
this.Write("\t</body>\r\n</html>\r\n");
#line default
#line hidden
- #line 48 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
+ #line 59 "D:\projects\dotnet\SharpDevelop.AspNetMvc\src\AddIns\BackendBindings\AspNet.Mvc\Project\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\Delete.tt"
}
#line default
Oops, something went wrong.

0 comments on commit 6ebfe59

Please sign in to comment.