Hey everyone,

I have this problem. I need to access data that the user inputs via the <input /> statement during the controller method.

Here's my code, maybe this will make it more clear:

// client side
@using (Html.BeginForm())
{
    if (competitorList.Count > 0 && eventList.Count > 0)
    {
        foreach (Event evt in eventList)
        {
            <table>
            <tr><th>@evt.activity.Name</th></tr>
            <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Score</th>
            <th>New Score</th>
            <th>Update</th>
            </tr>
            @foreach (Results res in resultList)
            {
                if (res.EventID == evt.id)
                {
                    string competitorName = Person.getUserByEmail(res.CompetitorEmail).FirstName + Person.getUserByEmail(res.CompetitorEmail).LastName;


                    <tr>
                        <td>@competitorName</td>
                        <td>@res.CompetitorEmail</td>
                        <td>@res.Score</td>
                        <td><form action="EventResults"><input type="text" name="score" id="score" /></form></td>
                        <td>@Html.ActionLink("Update", "UpdateResults", "Competition", new { compId = evt.competitionId, evtId = res.EventID, email = res.CompetitorEmail }, null)</td>
                    </tr>
                }
            }
            </table>
            <hr />
        }
    }
    else
    {
        <p>There are currently no competitors invited to participate</p>
    }
}


// controller
public ActionResult UpdateResults(FormCollection form, int compId, int evtId, string email)
        {
            //////     this returns 0.0     /////
            double score = Convert.ToDouble(form["score"]);

            BINC.Models.Results.UpdateResults(evtId, email, score);

            List<Event> CompetitionEvents = Event.getEventsByCompetitionId(compId);
            ViewBag.CompetitionEvents = CompetitionEvents;

            List<Competitor> Competitors = Competitor.getCompetitors(compId);
            ViewBag.Competitors = Competitors;

            List<Results> Results = Competition.getCompetitorResultsPairings(CompetitionEvents, Competitors);
            ViewBag.Results = Results;

            ViewBag.Competition = Competition.getCompetitionById(compId);

            return View("EventResults");
        }

Can someone give me a hand?

You Cannot open a form within a form:
your code says, "@using (Html.BeginForm())" then later says, "<form...."
Get rid of your secoond form and use @Html.EditorFor(res.Score)

OR

Start a new form for each iteration and get rid of the encapsulating @using(Html.BeginForm....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.