asp.net mvc - How can I validate a ViewModel in jQuery Dialog? -
My address is a bunch of attributes that mark in EditViewModel [Required (error message = "My error message here ")]
and / or [DisplayName (" etc. ")]
. Performance Name Features Functions:
<%: HTML.LabelFor (model => model.Field)%>
, and I think essential features are also working, but I do not know how to provide feedback on the form (jQuery UI Dialog). This form is deposited through $ .a.x (), and in the action method:
[htmlpost] public action result edit (addressAdvetyvailmodel address) {var addressTitit = DC adressers. FirstOther Default (X => X.AddressID == Address. AddressIDDIT); If (ModelState.IsValid) make sure that there is at least one active address (if! Address.ActiveEdit and address adobeit! = Blank & amp; adressiveActive) (if (DC Edres. (X = & gt ; X.ProfileID == addressToEdit.ProfileID) .net (x = & gt; x.actactive) == 1) {address.ActiveEdit = true;}} Try {// TryUpdateModel SUCKS!} / Usage prognostic address. ToEdit InjectFrom & lt; VMToAddress & gt; (Address); dc.SubmitChanges ();} Catch (Exception) {Return View (Address);}} and {Redirect Active Directory} Return material ("Right");}
and the small class for ValueInjecter:
public class VMToAddress: LoopValueInjection {protected override string TargetPropName (string sourcePropName) { If (sourcePropName.EndsWith ("edit")) {source sourceprog name., Rivosphix ("edit");} and if (sourcePropName.EndsWith ("create") {source sourcepropname. RemovesSuffix ("create");} And {return sourceprog name}}}}
ModelState.IsValid returns though even though address.RequiredField
is zero. SubmitChanges ()
throws a SqlException because it can not contain NULL values, I do not understand how to use modelstate, or is there any other way to react to an invalid area ? I would like to set a red border around my text box as I have seen model recognition in MVC tutorials, or maybe displaying my error message from ViewModel.
Another edit
created a client model binder to adjust the removed jQuery.validate and usually named elements. Custom model binders still add verification messages (so I deleted the call from Html.ValidationMessageFor (...)
because I do not want them - just limitations).
However, to use the jQuery.form plugin on Omu's suggestion, my model seems lost after the first postback. Checks for closeEditForm
bus content ("OK")
, closes the dialog, and finally refreshes the list dialog. But, after an error, it does not stop communicating properly, gives me red limitations, but in the subsequent posts, my binder has no model (bu) - only Zero value
$ ('# editform'). Submit (function () {$ (this) .ajaxSubmit ({target: '#editform', // will allow this to include validation classes, etc. Success: closeEditForm // If the response text is "OK" Will close "}"); returning false;});
I submit the form this way:
$ ("# dialog-address-edit"). Dialog ({... ... many dialog settings button: {'save': function () {$ ('# editform'). Submit ();
I recommend you use the jquery.form plugin and if the modelstate is good then you return the content ("OK") and You will see (your videodel), the customer will see that the reaction is fine, you close the dialog and you fill it with feedback (which is html)
you here I can see: I did a lot of AJAX in this project with jquery.form, although I did not use it, it was not necessary to return the html in AJAX reponse cuz
Comments
Post a Comment