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
11 Réponses
+ 1
I created another project
Here is the code : https://code.sololearn.com/cMrB8xmy3byS
+ 1
Yeahhhhhhhhhhhhhhhhhhhhhhhhhhhh
I saw that before you write me.
Goooddddddd Thank you a lot for your help. It works fine.
+ 1
ah okey good. thank you for your help.
Good person.
talk to you another time.
bye.
0
Before the textField i puted:
@using (Html.BeginForm())
In my routes i have:
controller ="Connexion", Action="VerifyDataAccount"
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
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.
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" }
);
0
If I don't create a route , how can i show the message : welcome viewData["utilisateur_key"].
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
0
okey thank you. but unfortunetly SoloLearn does not give oportunity to send private message.
thank you.
0
okey thank you. but idon't see the option for mailing you in your profile.