I have two input amount fields and a submit button on a form in the ASP.NET MVC4 application. If both amounts are left blank before submitting, server-side verification tells two error messages that ask to fill one or the other requirements. Until then everything works fine.
Even then, if I enter an amount and click submit, then the form is not submitted, instead the error in the box of that amount disappears. I really need to click Submit another time to submit the form correctly.
I think due to jquery error (due to initial error) disappears due to error, when the box loses focus, as I click submit. How can I ensure that the submission of the form is also submitted for the first time by clicking on submission?
See:
@ Model testostrosiv.models. Tradeview Model @ {ViewBag.Title = "Home Page"; } @ Use (html.BeginForm ("Index", "Home", FormMethod.Post, New {@class = "form-horizontal", role = "form"})) {& lt; Div class = "form-group" & gt; @ Html.LabelFor (model => model.Amount1, new {@class = "control-label col-md-3"}) & lt; Div class = "col-md-2" & gt; @ Html.TextBoxFor (model => model.Amount1, "{0: f2}", new {@class = "form-control", min = "0", type = "number", phase = "1000" }) @html Validity Message (Model => Model America1) & lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; @ Html.LabelFor (model => model.Amount2, new {@class = "control-label col-md-3"}) & lt; Div class = "col-md-2" & gt; @ Html.TextBoxFor (model = & gt; model.Amount2, "{0: f2}", new {@class = "form-control", min = "0", type = "number", phase = "1000" }) @html Validity message (Model = & gt; Model. AMOUNT 2) & lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "col-md-2" & gt; & Lt; Input type = "submit" value = "submit" data-loading = text = "submit ..." class = "BTN BTN-LG BTN-block" & gt; & Lt; / Div & gt; } @ Section scripts {@ Scripts.Render ("~ / bundles / jqueryval"}}
Model:
using the system; Using System.Collections.Generic; Using System.ComponentModel; Using System.ComponentModel.DataAnnotations; Using System.Linq; Using System.Web; Namespace TestVibrative.Models {PUBLIC CLASS COMMERCIAL MODEL: Official Object {[DisplayName ("Zodiac 1")] Public Decimal? Zodiac 1 {Receive; Set; } [DisplayName ("zodiac 2")] Public Decimal? Get 2; Set; } Public IEnumerable & lt; Validation result & gt; Validate (Validation Context Verification Consult) {Decimal? TransactionAmount = Amount1.HasValue? Amount 1: Amount 2 Haas Valleu? Zodiac 2: Zero; If returns (transaction money == zero) returns new verification result ("A value should be provided for either amount 1 or amount 2", new [] {"Amount1", "Amount2"}); }}}
Controller:
using the system; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.Mvc; Using TestObtrusive.Models; Namespace TestOustive Controllers {Public Class Home Controller: Controller {Public Performance Index} {Return View (); } [Http post] Public Action Result Index (Trade Vime Model Client Tradewide Module) {if (ModelState. ISWALID) {ViewBag.Title = "Results of page after submitting"; See Return ("Result"); } And {return view (); }}}}
Comments
Post a Comment