asp.net mvc - why model posted to action Display in view? -


There are 2 verbs with the same name. (AddNewUser) One of them works with HttpGet and the second HTTP post. [HTTPGet] Add Public Activity AddNewUser () {User User = Utilities. Session Provider. GETCurrentUser (); If (user.ID_User == 0) Return Direct ("Apps.kosarfci.ir"); RoleType role = (RoleType) RoleDeterminer.RoleDeterminate (); If (Role! = RoleType.Center) {Return Redirect ToAction ("Ban"); } See Return ("Venue User"); } [Http post] Public Action Result AddNewUser (VMNewUser InModel) {User User = Utilities. Session provider GETCurrentUser (); If (user.ID_User == 0) redirect return ("Apps.kosarfci.ir"); RoleType role = (RoleType) RoleDeterminer.RoleDeterminate (); If (Role! = RoleType.Center) {Return Redirect ToAction ("Ban"); } IUserBL Center UsherBel = New Center User BL (); InModel.User.UserName = InModell.User.NationalCode; InModel.User.Password = InModell.User.PersonalCode; Confirm of BULLBL = CenterUsbLl Edusor (inmoded user); _msgList.Add (New Message () {MsgType = Message Type. Success, MsgContent = Message Provider. GetMessage (MessageContent.Submit_Success_NewUser)}); ViewBag.Message = _msgList; See Return ("Venue User"); }

AddNewUser (), return a form with the input entry and then the form submitted to AddNewUser (VMNewUser InModel). But after this, a form filling with the post model is displayed. I hope that a form with a blank input entry display because I do not send a pre-filled model (VMNewUser) in the scene?

- VMNewUser -

@ Model Person Management View. User Vm new user

  & lt; Style & gt; Table {font-family: Tahoma; } & Lt; / Style & gt; @Usage (Html.BeginForm ("AddNewUser", "User", FormMethod.Post)) {& lt; Table & gt; & Lt; TR & gt; & Lt; TD & gt; Name & lt; / TD & gt; & Lt; TD & gt; @ Html.TextBoxFor (f = & gt; f.User.FirstName) & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Family & lt; / TD & gt; & Lt; TD & gt; @ Html.TextBoxFor (f = & gt; f.User.LastName) & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Personalcode & lt; / TD & gt; & Lt; TD & gt; @ Html.TextBoxFor (f = & gt; f.User.PersonalCode) & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Nationalcode & lt; / TD & gt; & Lt; TD & gt; @ Html.TextBoxFor (f = & gt; f.User.NationalCode) & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; td colspan = "2" & gt; Input  gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; }    

The main reason to send back the model of the population is to stop the user from stopping If there is an error in processing server-side, then refilling the form. It tells the client what field has failed and if any special error message should be displayed.

It is recommended that if this request is is successful, you will redirect the user to a new page. In your case, you can send the user back in the AddNewUser operation that will present the user with an empty form. for example.

  Redirect Return ("AddNewUser");    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -