I am using jQuery Ajax, and I have success: function (msg) ...
. When I specify when the hit will be: Error: Function (msg) ...
An issue seems to be that I have no way to go back True
or false
, because I have to return a view. In a normal web app (contrary to MVC), I used to return only true or wrong, then I can see this boolean value and work accordingly.
How can I specify that I want to jump in some cases error: for function (msg)
? For example, when verification is not passed, then I do not want to say that this is a success. Here is my JQuery code:
function contact dialog (action, controller) {var url = '/' + + action + '/' + controller; $ ("# Contact Dialogue"). Dialog ({autoOpen: true, hide: "fade", show: "bounce", height: $ (window). Light () / 2, width: $ (window). Method () / 2, title: "An email Send ", button: [{Text:" Send ", click: function () {$ .ajax ({url: url, data: $ (" form "). Serialize (), Reference: This, contentType: 'application / Html; charset = utf-8 ', datatype: "html", success: function (msg) {$ (this) .dialog ("off"); sent-response message (' msgSent ');}, error: work } {SendConfirmMessage ('msgNotSent');}}}}}}, {text: "cancel", click: function () {$ (this) .dialog ("close");}}]});
} and my HTML code which verifies:
@HTML Validity message (model => model. Subject) & lt; Br / & gt; @ Html.LabelFor (model => model.from) @ Html.TextBoxFor (model = & gt; model.first, new {@class = "AboutControls"}) & lt; Br / & gt; @html Validity message (Model = & gt; from model) & lt; Br / & gt; @htmllabelfor (model = & gt; model.bd) @html TextArfaf (model = & gt; model.bd, new {@ class = "control text array about control"}) public partial visual messaging mail (email model model) {if ( ModelState.IsValid) {mailMsg} = New MailMessage (model.from, receiver, model.shtml, model.body); Smtp.Send (mailMsg); Back partial view (about "_"); } ...
There is no way to know jQuery's Ajax code when it's success or failure with the above or code, because I can not say return true
or return false
hope that I am expressing myself
Take action in your MVC controller:
var status = new HTTP tags (); If (DataIsInvalid) // Whatever verification you need to do is {status = HttpStatusCode.BadRequest; } // Any other verification new HTTTPTus code result (status);
If you need to change it back then it does not trigger error
in your AJX, either leave status
or set Make this the HTTTPTAS code. OK
No comments:
Post a Comment