Please forgive me as I am just learning MVC3.
I have 2 db tables one for competitions and one for answers. For each competition there will be 3 answers associated with it.
My Create view is strongly typed to my competition model. What I want to do is add 3 unbound input boxes to that view and retrieve the results in the controller
My controller looks like this
Function Create(competition As Competition) As ActionResult
If ModelState.IsValid Then
db.Competitions.AddObject(competition)
db.SaveChanges()
Return RedirectToAction("Index")
End If
ViewBag.ClientID = New SelectList(db.Clients, "ClientID", "ClientName", competition.ClientID)
Return View(competition)
End Function
What i would like to do is something like this
Function Create(competition As Competition) As ActionResult
If ModelState.IsValid Then
'DIM ANSWERA AS STRING = INPUTA
'DIM ANSWERB AS STRING = INPUTB
'DIM ANSWERC AS STRING = INPUTC
db.Competitions.AddObject(competition)
db.SaveChanges()
'SAVE ANSWERS TO ANSWER TABLE
Return RedirectToAction("Index")
End If
ViewBag.ClientID = New SelectList(db.Clients, "ClientID", "ClientName", competition.ClientID)
Return View(competition)
End Function
Sorry if I have not formatted the question properly. Hopefully you get the gist of what I am trying to do
thanks
I got the above working by now I want to be able to edit competition details in a view
Function Edit(id As Integer) As ViewResult
Dim competition As Competition = db.Competitions.Single(Function(c) c.CompetitionID = id)
ViewBag.ClientID = New SelectList(db.Clients, "ClientID", "ClientName", competition.ClientID)
Return View(competition)
End Function
So I scaffold the view which returns my competition details but how do I add 3 input boxes to display the 3 answers associated with that competition?
Request("NAME")will look for NAME as the name of a form element, cookie, querystring parameter or server variables.To be safe you should probably specifically target the form element called “answerA” using:
but either of the two examples above will work.