c# - Show validation message, but clear value -
I'm searching around and I feel like a normal requirement but I can not find an answer: / P>
With MVC data entry verification, you can show the verification message ('Maximum length should be 5 string with') in the summary of the verification, but clear the value of the text box (when
I used to use the I am asking because because we had an entrance examination recently and from the recommendations A was not pre-populated secure value (credit card number etc.) if verification fails. This is clearly a minor case, but the recommendation was not to send the value back to the server (from the server) , If we do not Land. There have been code I have ever worked with: More visual models: More views: The modelstate of each field only keeps more than the value, Completely deleted your error message as expected. I believe that you have to do something, however, only that value should be able to clean. ModelState.Clear () and ModelState.Remove ("CompanyName") It clears, both the value and verification message (verification status).
Edit public function () {return View (); } [Http post] Edit the Public Action Result (Company Input Input) {if (ModelState.IsValid) {Return View ("Success"); } //ModelState.Clear // has approved both the value and verification message. //ModelState.Remove("CompanyName ") // Return Similar Results Return (New CompanyInput ()); }
public class companyInput {[required] [string lang (5)] public string companyName {get; Set; } [Datatype (datatype e-mail account)] {get public string email address; Set; }}
@ Model Test. Models. Company input & lt; H2 & gt; Edit & lt; / H2 & gt; @using (Html.BeginForm ("edit", "company")) {@ Html.EditorForModel () & lt; Button type = "submit" & gt; Submit & lt; / Button & gt; }
ModelState ["Company name"]. Value = zero; Edit: After the close inspection I found that the value of the property is ValueProviderResult , simply the result of not filling it is not desired, and because the properties of this category are the recipients only You have to replace your own example I have tested the following and it works for me.
ModelState ["Company name"]. Value = new value provider result (string.opti, string.opt, modelstate ["company name"]. Value; culture);
Comments
Post a Comment