0

Pass data of a textField to a Model in order to use by a controller

In my view Index.cshtml, i have a form for authentification. I created the textfield like this : @Html.TextBoxFor(model => model.Username). For testing if everything is okey, i would like to show what i enter in the field of Username. Public ActionResult VerifyDataAccount(Account acc) { viewData[‘’user_name’’] = acc.Username; return View(‘’viewUsername’’); } In the View viewUsername.cshtml i puted : Hello @viewData["’user_name’’"] 1.The username is never show 2. Is it necessary to put [HttpPost] ? thanks

7th Nov 2017, 5:45 PM
Attitude
Attitude - avatar
11 odpowiedzi
+ 1
I created another project Here is the code : https://code.sololearn.com/cMrB8xmy3byS
8th Nov 2017, 1:03 AM
Attitude
Attitude - avatar
+ 1
Yeahhhhhhhhhhhhhhhhhhhhhhhhhhhh I saw that before you write me. Goooddddddd Thank you a lot for your help. It works fine.
8th Nov 2017, 2:05 AM
Attitude
Attitude - avatar
+ 1
ah okey good. thank you for your help. Good person. talk to you another time. bye.
8th Nov 2017, 2:23 AM
Attitude
Attitude - avatar
0
Before the textField i puted: @using (Html.BeginForm()) In my routes i have: controller ="Connexion", Action="VerifyDataAccount"
7th Nov 2017, 8:08 PM
Attitude
Attitude - avatar
0
Thank you Jamie for your answer. But i have an error. I don't know if you'll understand French! La demande actuelle pour l'action « ValiderConnexion » sur le type de contrôleur « ConnexionController » est ambiguë entre les méthodes d'action suivantes : System.Web.Mvc.ActionResult ValiderConnexion() sur le type JCorrespondance.Controllers.ConnexionController System.Web.Mvc.ActionResult ValiderConnexion(JCorrespondance.Models.Connexion) sur le type JCorrespondance.Controllers.ConnexionController
8th Nov 2017, 1:32 AM
Attitude
Attitude - avatar
0
I don't have the error now. But it doesn't show me the name of the user, after doing what you suggest me.
8th Nov 2017, 1:38 AM
Attitude
Attitude - avatar
0
Yes i remove it and i did not have the error. But it doesn't show me what i puted in the textField username. Here is my route: routes.MapRoute( name: "connexion", url: "{controller}/{action}", defaults: new { Controller = "Connexion", Action = "ValiderConnexion" } );
8th Nov 2017, 1:42 AM
Attitude
Attitude - avatar
0
If I don't create a route , how can i show the message : welcome viewData["utilisateur_key"].
8th Nov 2017, 1:54 AM
Attitude
Attitude - avatar
0
Yeah, thank you. I'm so happy. I'm going to bed gald. Why it's work even if i don't use tag [HttpPost] in the action ValiderConnexion
8th Nov 2017, 2:10 AM
Attitude
Attitude - avatar
0
okey thank you. but unfortunetly SoloLearn does not give oportunity to send private message. thank you.
8th Nov 2017, 2:30 AM
Attitude
Attitude - avatar
0
okey thank you. but idon't see the option for mailing you in your profile.
8th Nov 2017, 11:57 AM
Attitude
Attitude - avatar