hncl
hncl

Reputation: 2295

MVC Form post Html.BeginForm ASPX view

This question might be very simple to many of you, but I am just learning. Trying to convert form to Html.BeginForm

The old script is

<form method="POST" name="myquiz">

Trying to convert it to

<% Html.BeginForm(new {name="myquiz"}); %>
<input type="button" value="Grade Me!" name="B1" onclick="gradeit()" class="t-button"/>
<input type="button" value="Reset" name="B2" onclick="document.myquiz.reset()" class="t-button"/>
<% Html.EndForm(); %>

When I click on reset button, I get the following error:

 Unable to get property 'reset' of undefined or null reference

Would appreciate your suggestions.

Upvotes: 0

Views: 369

Answers (2)

Moho
Moho

Reputation: 16498

Your anonymous class object paramter is passed as the route values, not HTML attibutes, you need, at a minimum, this many parameters to get what you want (MSDN):

Html.BeginForm(null, null, FormMethod.Post, new { name = "myquiz" })

Upvotes: 0

Max
Max

Reputation: 1150

Too few params, see MSDN for details, so it should be:

HTML.BeginForm(null,null,FormMethod.Post, new {@name="myquiz", id="myquiz"})

Upvotes: 1

Related Questions