我有这个问题。我需要在控制器方法期间通过语句访问用户输入的数据。
这是我的代码,也许这会让它更清楚:
// 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");
}
您在控制器方法中看到的内容不起作用;我认为这是因为该页面实际上并未“提交”?我真的很想使用链接而不是提交按钮。有人可以帮帮我吗?