2
Answers

MVC Data Binding

Randy Rutecki

Randy Rutecki

7y
197
1
I am trying to bind a value from a button to submit to a DB. I see that the view created a way to bind the value to a form textbox:
 
 @Html.EditFor(model => model.TeamNumber, New { htmlAttributes = new { @class = "form-control" } } )
 
 This works great if I wanted to add the TeamNumber in the textbox, but I have a series of buttons with the game schedule of teams for the week and when I click on one I am able to use jQuery to access the teamID's for the teams I want to select but need to save the selected teams to the db.
 
i have the db and class for 5 teams team1, team2 team3 etc. that I could save using the above binding but I want to know how to take the team1Id value from the button click and bind it to the model as if I had entered it in the text box.
 
Any help would be greatly appreciated.
Thanks
 
Answers (2)
0
Manikandan Murugesan

Manikandan Murugesan

NA 20.5k 98.9k 7y
Refer the following Links : https://www.codeproject.com/Articles/551576/ASP-NET-MVC-Model-Binding-and-Data-Annotation
 
http://www.c-sharpcorner.com/UploadFile/4b0136/introduction-to-model-binding-in-Asp-Net-mvc/
 
https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding 
Accepted
0
Randy Rutecki

Randy Rutecki

NA 24 775 7y
Thank you I am looking at the article Model Binding in MVC : A Magical Mapper. 
Love the C# Corner great place for information.
 
Thanks again!