Last post Mar 11, 2008 04:14 AM by astaykov
Mar 10, 2008 04:38 PM|astaykov|LINK
I am playing with the Preview 2 of the MVC Framework and noticed something strange:
When I use the "Html" property (HtmlHelper Instance) in a ViewPage to render a FORM tag like this:
<%= Html.Form("MyController", "MyAction") %>
I end up with this markup:
<form action="/MyController/MyAction" method="post" >System.Web.Mvc.SimpleForm
Please note the "System.Web.Mvc.SimpleForm" - it is not my mistake - it comes out in the markup regardless of the Build Configuration (Debug or Release).
Is this some bug, or I do something wrong?
Mar 11, 2008 04:14 AM|astaykov|LINK
After several more scenarios I revealed the strange, may be, behavior of that extension method.
We should use <% Html.Form("MyController", "MyAction") %> instead of <%= Html.Form("MyController", "MyAction") %>,
Because the helper method Form(HtmlHelper, string ControllerName, string ControllerAction) is writing directly onto the Context, instead of returning a string. So when we use the <%= %> syntax, it will first write the output to the current Context, and then
will output the type that is writing - in this case System.Web.Mvc.SimpleForm.
I think this is a strange behavior, because no other helper method (like Button, Hidden, etc.) is writing to the context, but is returning a string.