C# mvc2 client side form validation with xval, prevent post

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-16T11:55:08Z Indexed on 2010/04/16 14:33 UTC
Read the original article Hit count: 621

Filed under:
|
|
|
|

I'm using xval to use client side validation in my asp.net mvc2 webapplication. Despite the errors it's giving when i enter text in a nummeric field it still tries to post the form to the database. The incorrect values are being replaced by 0 and saved to the database. But instead it shouldn't even be possible to try and submit the form. Can anyone help me out here?

I've set the attributes as below;

[Property]
[ShowColumnInCrud(true, label = "FromPriceInCents")]
[Required]
//[Range(1, Int32.MaxValue)]
public virtual Int32 FromPriceInCents{ get; set; }

The controller catching the request looks as below; I'm getting no errors in this part.

[AcceptVerbs(HttpVerbs.Post)]
[Transaction]
[ValidateInput(false)]
public override ActionResult Create()
{
  //some foo happens
}

My view looks like below;

<div class="label"><label for="Price">FromPrice</label></div>
<div class="field">
<%= Html.TextBox("FromPriceInCents")%>
<%= Html.ValidationMessage("product.FromPriceInCents")%></div>

And at the end of the view i have the following rule which in html code generates the correct validation rules

<%= Html.ClientSideValidation<Product>("Product") %>

I hope someone can helps me out with this issue, thanks in advance!

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc