How to implement input masking with ASP.NET MVC

女生的网名这么多〃 提交于 2019-12-24 15:30:56

问题


I'm working on a form with ASP.NET MVC and am trying to figure out how best to implement input masking (e.g. for phone number or US zip code). Are there any commonly accepted approaches here for the data types I should use in my model. This question suggests to use a long for phone number and using a DisplayFormat attribute on the model field but it seems to conflict with validation. I don't really mind converting from one type in my view model to another type in my data models, but would like to chose an approach which sits well with jQuery unobtrusive validation.


回答1:


I personally like using the Masked Input Plugin. You set up the mask in JavaScript, so it is unobstrusive, but it does not use data-* attributes.

In the project I'm working on, we do use long to store the phone number, which personally I do not like.



来源:https://stackoverflow.com/questions/20100838/how-to-implement-input-masking-with-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!