-1

I need to check some condition and based on that run a jQuery function on keypress for validate key.

I have 3 types for validate.

  • text
  • Integer, decimal or double
  • formula and I want get number and some formula sign for example gets only (*-/+) and number.

How can I do it ? Any help ?

@for(int i = 0 ; i < Model.ParamStructList.Count ; i++)
{
   @Html.TextBox("ParamStructList["+i+"].value",Model.ParamItemValueList[i].Value,new{onkeypress=""})
}
Ali Soltani
  • 9,589
  • 5
  • 30
  • 55
Zebra
  • 66
  • 12
  • 1
    Read up on unobtrusive validation: https://www.exceptionnotfound.net/asp-net-mvc-demystified-unobtrusive-validation/ – zaitsman Jul 10 '16 at 08:04
  • @zaitsman ur answer not related to my question ,I dont want define attribute for fields in viewmodel.I want check condition in view . – Zebra Jul 10 '16 at 08:07
  • if you read the article you will see that is EXACTLY what unobtrusive validation gives you. – zaitsman Jul 10 '16 at 08:07
  • In additional,I check condtion by an enum type. – Zebra Jul 10 '16 at 08:08
  • 1
    Of course you can roll with any kind of stuff you want :) the unobtrusive validation is a fairly standard, cheap and no effort required feature provided by Microsoft for a few years. If you prefer to roll your own framework, you're welcome to. I suggest it would be hard to find someone to write it for you, though, as the question as you've asked it is ways too broad. – zaitsman Jul 10 '16 at 08:15

1 Answers1

0

You can use DataType and RegularExpression attribues in model.(see this)

Community
  • 1
  • 1
Ali Soltani
  • 9,589
  • 5
  • 30
  • 55