0

I need to validate my editor field for entering the price of product like he can enter integer as 100,or after decimal only allows two digits as 85.12,and if user enters 85,12 also it is valid and it stores in database as 85.12. model class:

[Required]

[LocalizedDisplayName("PRICE_PER_COLLI", NameResourceType = typeof(Strings))] [DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]

public decimal ColliPrice { get; set; }

View:

<%: Html.EditorFor(model => model.ColliPrice) %> 
<%: Html.ValidationMessageFor(model => model.ColliPrice)  
1
  • <%: isn't MVC 3 format? Don't you mean MVC2?? Commented Sep 27, 2012 at 8:40

1 Answer 1

1

I've done this before like:

@Html.TextBox("ColliPrice", Model.ColliPrice.ToString("0.00")) 
@Html.ValidationMessageFor(model => model.ColliPrice)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.