This project is read-only.

Unit Testing: Missing <form> element in HTML rendered by RenderAsHtml

Feb 1, 2012 at 6:46 PM

I have the following cshtml file:

@* Generator : MvcView *@
@model TestGrid.Views.Account.LogOnViewModel
    ViewBag.Title = "LogOn";

@{ Html.BeginForm("LogOn", "Account", new { ReturnURL = Model.ReturnURL }); }
    Name: @Html.TextBoxFor(m => m.UserName)
    Password: @Html.PasswordFor(m => m.Password)
    <input type="submit" value="submit" />
@{ Html.EndForm(); }

When I try to render it with RenderAsHTML via "HtmlDocument doc = view.RenderAsHtml(model);", I get the following value for doc.Text.

"\r\n\r\n<h2>LogOn</h2>\r\n    Name: <input id=\"UserName\" name=\"UserName\" type=\"text\" value=\"\" />\r\n    Password: <input id=\"Password\" name=\"Password\" type=\"password\" />\r\n    <input type=\"submit\" value=\"submit\" />\r\n"

Should the Text value include the <form></form> tags?