();
+ }
+
+ return _endOfFormContent;
+ }
+ }
+
+ public bool CanRenderAtEndOfForm { get; set; }
+
public bool RenderedField(string fieldName)
{
if (fieldName == null)
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs
index dccea37903..fbd327e4d9 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs
@@ -272,12 +272,24 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
FormMethod method,
object htmlAttributes)
{
+ // Push the new FormContext; MvcForm.GenerateEndForm() does the corresponding pop.
+ _viewContext.FormContext = new FormContext
+ {
+ CanRenderAtEndOfForm = true
+ };
+
return GenerateForm(actionName, controllerName, routeValues, method, htmlAttributes);
}
///
public MvcForm BeginRouteForm(string routeName, object routeValues, FormMethod method, object htmlAttributes)
{
+ // Push the new FormContext; MvcForm.GenerateEndForm() does the corresponding pop.
+ _viewContext.FormContext = new FormContext
+ {
+ CanRenderAtEndOfForm = true
+ };
+
return GenerateRouteForm(routeName, routeValues, method, htmlAttributes);
}
@@ -708,13 +720,24 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
isChecked,
htmlAttributes);
- var hidden = _htmlGenerator.GenerateHiddenForCheckbox(ViewContext, modelExplorer, expression);
- if (checkbox == null || hidden == null)
+ var hiddenForCheckboxTag = _htmlGenerator.GenerateHiddenForCheckbox(ViewContext, modelExplorer, expression);
+ if (checkbox == null || hiddenForCheckboxTag == null)
{
return HtmlString.Empty;
}
- return new BufferedHtmlContent().Append(checkbox).Append(hidden);
+ var checkboxContent = new BufferedHtmlContent().Append(checkbox);
+
+ if (ViewContext.FormContext.CanRenderAtEndOfForm)
+ {
+ ViewContext.FormContext.EndOfFormContent.Add(hiddenForCheckboxTag);
+ }
+ else
+ {
+ checkboxContent.Append(hiddenForCheckboxTag);
+ }
+
+ return checkboxContent;
}
protected virtual string GenerateDisplayName(ModelExplorer modelExplorer, string expression)
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.EmployeeList.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.EmployeeList.html
index 180133efc1..daacb9b15f 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.EmployeeList.html
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.EmployeeList.html
@@ -24,7 +24,7 @@ EmployeeName_0
-
+
@@ -55,7 +55,7 @@ EmployeeName_1
-
+
@@ -86,7 +86,7 @@ EmployeeName_2
-
+
@@ -94,5 +94,5 @@ EmployeeName_2
-