();
+ }
+ return this.indents;
+ }
+ }
+
+ public ToStringInstanceHelper ToStringHelper {
+ get {
+ return this._toStringHelper;
+ }
+ }
+
+ public void Error(string message) {
+ this.Errors.Add(new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message));
+ }
+
+ public void Warning(string message) {
+ global::System.CodeDom.Compiler.CompilerError val = new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message);
+ val.IsWarning = true;
+ this.Errors.Add(val);
+ }
+
+ public string PopIndent() {
+ if ((this.Indents.Count == 0)) {
+ return string.Empty;
+ }
+ int lastPos = (this.currentIndent.Length - this.Indents.Pop());
+ string last = this.currentIndent.Substring(lastPos);
+ this.currentIndent = this.currentIndent.Substring(0, lastPos);
+ return last;
+ }
+
+ public void PushIndent(string indent) {
+ this.Indents.Push(indent.Length);
+ this.currentIndent = (this.currentIndent + indent);
+ }
+
+ public void ClearIndent() {
+ this.currentIndent = string.Empty;
+ this.Indents.Clear();
+ }
+
+ public void Write(string textToAppend) {
+ if (string.IsNullOrEmpty(textToAppend)) {
+ return;
+ }
+ if ((((this.GenerationEnvironment.Length == 0)
+ || this.endsWithNewline)
+ && (this.CurrentIndent.Length > 0))) {
+ this.GenerationEnvironment.Append(this.CurrentIndent);
+ }
+ this.endsWithNewline = false;
+ char last = textToAppend[(textToAppend.Length - 1)];
+ if (((last == '\n')
+ || (last == '\r'))) {
+ this.endsWithNewline = true;
+ }
+ if ((this.CurrentIndent.Length == 0)) {
+ this.GenerationEnvironment.Append(textToAppend);
+ return;
+ }
+ int lastNewline = 0;
+ for (int i = 0; (i
+ < (textToAppend.Length - 1)); i = (i + 1)) {
+ char c = textToAppend[i];
+ if ((c == '\r')) {
+ if ((textToAppend[(i + 1)] == '\n')) {
+ i = (i + 1);
+ if ((i
+ == (textToAppend.Length - 1))) {
+ goto breakLoop;
+ }
+ }
+ }
+ else {
+ if ((c != '\n')) {
+ goto continueLoop;
+ }
+ }
+ i = (i + 1);
+ int len = (i - lastNewline);
+ if ((len > 0)) {
+ this.GenerationEnvironment.Append(textToAppend, lastNewline, (i - lastNewline));
+ }
+ this.GenerationEnvironment.Append(this.CurrentIndent);
+ lastNewline = i;
+ continueLoop:
+ ;
+ }
+ breakLoop:
+ if ((lastNewline > 0)) {
+ this.GenerationEnvironment.Append(textToAppend, lastNewline, (textToAppend.Length - lastNewline));
+ }
+ else {
+ this.GenerationEnvironment.Append(textToAppend);
+ }
+ }
+
+ public void Write(string format, params object[] args) {
+ this.Write(string.Format(format, args));
+ }
+
+ public void WriteLine(string textToAppend) {
+ this.Write(textToAppend);
+ this.GenerationEnvironment.AppendLine();
+ this.endsWithNewline = true;
+ }
+
+ public void WriteLine(string format, params object[] args) {
+ this.WriteLine(string.Format(format, args));
+ }
+
+ public class ToStringInstanceHelper {
+
+ private global::System.IFormatProvider formatProvider = global::System.Globalization.CultureInfo.InvariantCulture;
+
+ public global::System.IFormatProvider FormatProvider {
+ get {
+ return this.formatProvider;
+ }
+ set {
+ if ((this.formatProvider == null)) {
+ throw new global::System.ArgumentNullException("formatProvider");
+ }
+ this.formatProvider = value;
+ }
+ }
+
+ public string ToStringWithCulture(object objectToConvert) {
+ if ((objectToConvert == null)) {
+ throw new global::System.ArgumentNullException("objectToConvert");
+ }
+ global::System.Type type = objectToConvert.GetType();
+ global::System.Type iConvertibleType = typeof(global::System.IConvertible);
+ if (iConvertibleType.IsAssignableFrom(type)) {
+ return ((global::System.IConvertible)(objectToConvert)).ToString(this.formatProvider);
+ }
+ global::System.Reflection.MethodInfo methInfo = type.GetMethod("ToString", new global::System.Type[] {
+ iConvertibleType});
+ if ((methInfo != null)) {
+ return ((string)(methInfo.Invoke(objectToConvert, new object[] {
+ this.formatProvider})));
+ }
+ return objectToConvert.ToString();
+ }
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Details.tt b/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Details.tt
new file mode 100644
index 0000000000..bcd53dc576
--- /dev/null
+++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Details.tt
@@ -0,0 +1,60 @@
+<#@ template language="C#" HostSpecific="true" #>
+<#@ import namespace="ICSharpCode.AspNet.Mvc" #>
+<#@ output extension=".cshtml" #>
+<#= GetModelDirective() #>
+
+<#
+ if (MvcHost.IsPartialView) {
+ // Do nothing.
+ } else if (MvcHost.IsContentPage) {
+#>
+@{
+ ViewBag.Title = "<#= MvcHost.ViewName #>";
+ Layout = "<#= MvcHost.MasterPageFile #>";
+}
+
+<#= MvcHost.ViewName #>
+
+<#
+ } else {
+#>
+
+
+
+ <#= MvcHost.ViewName #>
+
+
+<#
+ PushIndent("\t\t");
+ }
+#>
+
+
+ @Html.ActionLink("Edit", "Edit") |
+ @Html.ActionLink("Back", "Index")
+
+<#
+ if (MvcHost.IsPartialView) {
+ // Do nothing.
+ } else if (!MvcHost.IsContentPage) {
+ PopIndent();
+#>
+
+
+<# } #>
+<#+
+ MvcTextTemplateHost MvcHost {
+ get { return (MvcTextTemplateHost)Host; }
+ }
+
+ public string GetModelDirective()
+ {
+ string viewDataTypeName = MvcHost.ViewDataTypeName;
+ if (!String.IsNullOrEmpty(viewDataTypeName)) {
+ return String.Format("@model {0}", viewDataTypeName);
+ }
+ return String.Empty;
+ }
+#>
\ No newline at end of file
diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Details.txt b/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Details.txt
new file mode 100644
index 0000000000..5f282702bb
--- /dev/null
+++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/ItemTemplates/CSharp/CodeTemplates/AddView/CSHTML/Details.txt
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj b/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj
index fdaaecfdf0..cd449b0a29 100644
--- a/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj
+++ b/src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj
@@ -90,6 +90,7 @@
+
diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpDetailsViewTemplateTests.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpDetailsViewTemplateTests.cs
new file mode 100644
index 0000000000..7569b1ac45
--- /dev/null
+++ b/src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/CodeTemplates/RazorCSharpDetailsViewTemplateTests.cs
@@ -0,0 +1,152 @@
+// 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;
+using AspNet.Mvc.Tests.CodeTemplates.Models;
+using AspNet.Mvc.Tests.Helpers;
+using ICSharpCode.AspNet.Mvc.CSHtml;
+using NUnit.Framework;
+
+namespace AspNet.Mvc.Tests.CodeTemplates
+{
+ [TestFixture]
+ public class RazorCSharpDetailsViewTemplateTests
+ {
+ Details templatePreprocessor;
+ TestableMvcTextTemplateHost mvcHost;
+
+ void CreateViewTemplatePreprocessor()
+ {
+ mvcHost = new TestableMvcTextTemplateHost();
+ templatePreprocessor = new Details();
+ templatePreprocessor.Host = mvcHost;
+ }
+
+ [Test]
+ public void GetModelDirective_HostViewDataTypeNameIsMyAppMyModel_ReturnsRazorModelFollowedByMyAppMyModel()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.ViewDataTypeName = "MyApp.MyModel";
+
+ string modelDirective = templatePreprocessor.GetModelDirective();
+
+ Assert.AreEqual("@model MyApp.MyModel", modelDirective);
+ }
+
+ [Test]
+ public void GetModelDirective_HostViewDataTypeNameIsNull_ReturnsEmptyString()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.ViewDataTypeName = null;
+
+ string modelDirective = templatePreprocessor.GetModelDirective();
+
+ Assert.AreEqual(String.Empty, modelDirective);
+ }
+
+ [Test]
+ public void GetModelDirective_HostViewDataTypeNameIsEmptyString_ReturnsEmptyString()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.ViewDataTypeName = String.Empty;
+
+ string modelDirective = templatePreprocessor.GetModelDirective();
+
+ Assert.AreEqual(String.Empty, modelDirective);
+ }
+
+ [Test]
+ public void TransformText_ModelHasNoPropertiesAndNoMasterPage_ReturnsFullHtmlPageWithFormAndFieldSetForModel()
+ {
+ CreateViewTemplatePreprocessor();
+ Type modelType = typeof(ModelWithNoProperties);
+ mvcHost.ViewDataType = modelType;
+ mvcHost.ViewDataTypeName = modelType.FullName;
+ mvcHost.ViewName = "MyView";
+
+ string output = templatePreprocessor.TransformText();
+
+ string expectedOutput =
+@"@model AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithNoProperties
+
+
+
+
+ MyView
+
+
+
+
+ @Html.ActionLink(""Edit"", ""Edit"") |
+ @Html.ActionLink(""Back"", ""Index"")
+
+
+
+";
+ Assert.AreEqual(expectedOutput, output);
+ }
+
+ [Test]
+ public void TransformText_ModelHasNoPropertiesAndIsPartialView_ReturnsControlWithFormAndFieldSetForModel()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.IsPartialView = true;
+ Type modelType = typeof(ModelWithNoProperties);
+ mvcHost.ViewDataType = modelType;
+ mvcHost.ViewDataTypeName = modelType.FullName;
+ mvcHost.ViewName = "MyView";
+
+ string output = templatePreprocessor.TransformText();
+
+ string expectedOutput =
+@"@model AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithNoProperties
+
+
+
+ @Html.ActionLink(""Edit"", ""Edit"") |
+ @Html.ActionLink(""Back"", ""Index"")
+
+";
+ Assert.AreEqual(expectedOutput, output);
+ }
+
+ [Test]
+ public void TransformText_ModelHasNoPropertiesAndIsContentPage_ReturnsContentPageWithFormAndFieldSetForModel()
+ {
+ CreateViewTemplatePreprocessor();
+ mvcHost.IsContentPage = true;
+ Type modelType = typeof(ModelWithNoProperties);
+ mvcHost.ViewDataType = modelType;
+ mvcHost.ViewDataTypeName = modelType.FullName;
+ mvcHost.ViewName = "MyView";
+ mvcHost.MasterPageFile = "~/Views/Shared/Site.master";
+ mvcHost.PrimaryContentPlaceHolderID = "Main";
+
+ string output = templatePreprocessor.TransformText();
+
+ string expectedOutput =
+@"@model AspNet.Mvc.Tests.CodeTemplates.Models.ModelWithNoProperties
+
+@{
+ ViewBag.Title = ""MyView"";
+ Layout = ""~/Views/Shared/Site.master"";
+}
+
+MyView
+
+
+
+ @Html.ActionLink(""Edit"", ""Edit"") |
+ @Html.ActionLink(""Back"", ""Index"")
+
+";
+ Assert.AreEqual(expectedOutput, output);
+ }
+ }
+}