控制器中的输入掩码 MVC 取消掩码 [英] Input mask MVC unmask in controller

查看:26
本文介绍了控制器中的输入掩码 MVC 取消掩码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MVC 5.2 .NET 4.5 中工作:

Im working in MVC 5.2 .NET 4.5:

任何人都可以向我指出一个 js 或其他库/方法来获取输入掩码,该掩码将取消掩码并将视图模型中输入的数据发送到控制器?

Can anyone point me to a js or other library / method for an input mask that will unmask and just send the entered data in the view model to the controller?

到目前为止我尝试过的任何可以取消屏蔽的 .js 库,仍然会将屏蔽发送到控制器.

Any .js library I've tried so far that can unmask, still sends the mask to the controller.

谢谢.

推荐答案

https://github.com/RobinHerbots/jquery.inputmask

将 autoUnmask 设置为 true 以进行客户端验证,将 removeMaskOnSubmit 设置为 true 以获取在服务器端验证或控制器中删除文字的输入.

Set autoUnmask to true for client side validation and removeMaskOnSubmit to true to get the input with the literals removed in the server side validation or controller.

使用此电话号码的编辑器模板示例:

Example of an editor template using this for a phone number:

@model string

@Html.TextBox("", Model, new { @class = "form-control" })

<script type="text/javascript">

$(function () {
    $('#@Html.IdForModel()').inputmask({ "mask": "(999) 999-9999", 'autoUnmask': true, 'removeMaskOnSubmit': true });
});
</script>

这篇关于控制器中的输入掩码 MVC 取消掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆