0

Hey everyone,

I'm having some problems with my code and was hoping someone could give me a hand. Here's the snippet I'm working with:

[Authorize]
        public ActionResult EventResults(int id)
        {
            List<Event> CompetitionEvents = Event.getEventsByCompetitionId(id);
            ViewBag.CompetitionEvents = CompetitionEvents;

            List<Person> Competitors = Competition.getCompetitorsByCompetitionID(id);
            ViewBag.Competitors = Competitors;

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

            ViewBag.OrganizerEmail = Competition.getCompetitionById(id).OrganizerEmail;

            return View();
        }



@model BINC.Models.Results
@using BINC.Models;

@{
    var eventList = ViewBag.CompetitionEvents as List<Event>;
    var competitorList = ViewBag.Competitors as List<Person>;
    var resultList = ViewBag.Results as List<Results>;
}

<h2></h2>

<p>Results:</p>
    @using (Html.BeginForm())
       {
            foreach (var evt in eventList)
            {
                <fieldset>
                    <legend>@evt.activity.Name</legend>

                   <p>Event Description:  @evt.activity.Description</p>
                   @foreach (var competitor in competitorList)
                   {
                       foreach (var result in resultList)
                       {
                           if (result.EventID == evt.id && result.CompetitorEmail == competitor.Email)
                           {
                               <p>Competitor:  @competitor.FirstName @competitor.LastName</p>
                               <p>Score:  @result.Score</p>

                               if (ViewBag.OrganizerEmail.Equals(@User.Identity.Name))
                               {
                                    @Html.LabelFor(model => model.Score, "New Score   ");
                                    @Html.TextBoxFor(model => model.Score, new { maxlength = 10, style = "width:125px" })
                                    <input type="submit" name="submitButton" value="Update" />
                               }
                           }
                       }
                   }
                </fieldset>
            }
       }






[HttpPost]
        public ActionResult EventResults(Results res)
        {
           //stuff
        }

My problem is I want to pass in the value of the current result-set, not the Result model object.
For example, when I put the value '15' into the text box and click 'Update', I'm passing the Result model object to the httppost method, which has everything set to null other than the 'score' field that I just entered.

Am I over complicating this? Is there an easier way?

Edited by Duki

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Duki
0

I tried using the following, but it didn't seem to work either:

 @Html.LabelFor(model => model.Score, "New Score   ");
                                @Html.TextBoxFor(model => model.Score, new { maxlength = 10, style = "width:125px" })
                                @Html.HiddenFor(model => model.EventID);
                                @Html.HiddenFor(model => model.CompetitorEmail);
                                <input type="submit" name="submitButton" value="Update" />
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.