Matt
Matt

Reputation: 2790

How do I get Asp.net MVC BeginForm to add closing tag correctly?

I seem to be missing something obvious here, but cannot see what it is.

My problem is that the closing form tag for BeginForm is not being added to my markup. I am looping through a collection and creating a form for each item, but the forms arent closing properly. Any suggestions please? Thanks

<% foreach (var item in Model) { %>  

<% using (Html.BeginForm("EditUser","Users"))
   { %>    
    <tr>           
        <td>
            <input id="contactID" type="hidden" value="<%= item.ContactID %>" />
            <%=item.Email %>
        </td>
        <td>
            <%=item.Market.MarketName%>
        </td>
        <td>
            <%=item.ContactType.ContactTypeName%>
        </td>
        <td>
            <input type="submit" value="Edit" />            
        </td>               
    </tr>
    <%} %>    
<% } %>

Upvotes: 2

Views: 1148

Answers (2)

fearofawhackplanet
fearofawhackplanet

Reputation: 53378

It's not valid HTML to have a form inside a table in that way. The markup looks fine, so I'm guessing this might be your issue. You could maybe try with the form inside the <tr> tags. If that still doesn't work, you might need to use a div based layout.

Upvotes: 1

dotcoder
dotcoder

Reputation: 2921

To me, the markup seems right. Perhaps you can try Html.BeginForm() and Html.EndForm() instead of "using" clause.

Upvotes: 1

Related Questions