0

I'm experimenting with ASP.NET MVC 2, and I have a simple form using Html.BeginRouteForm, which is working file, except it writes the string System.Web.Mvc.Html.MvcForm to the html.

Why does it do this and how can I get it to stop?


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SelectList>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Index</h2>

    <%=Html.BeginRouteForm(String.Empty, new {Action = "Search"}, FormMethod.Get) %>


    <%:Html.DropDownList("worklist", this.Model )%>

    <br />

    <input type="submit" />

    <% Html.EndForm(); %>
</asp:Content>

<h2>Index</h2>

<form action="/Site/Search" method="get">System.Web.Mvc.Html.MvcForm


<select Label="Worklists" id="worklist" name="worklist"><!-- Options -->
</select>

<br />

<input type="submit" />

</form>

1 Answer 1

2

Because you're calling it incorrectly. <%= means, more or less, "treat the result as a string." The default implementation of .ToString() writes the class name. You could use <% and that would fix the problem. But better still is to use it with using, which is more idiomatic for MVC and relieves you of the need to call EndForm explicitly. In other words, change your code:

<%=Html.BeginRouteForm(String.Empty, new {Action = "Search"}, FormMethod.Get) %>
    ...
<% Html.EndForm(); %>

... to:

<% using (Html.BeginRouteForm(String.Empty, new {Action = "Search"}, FormMethod.Get)) { %>
    ...
<% } %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.