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

查看:226
本文介绍了控制器中的输入掩码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天全站免登陆