Input mask MVC unmask in controller

2019-09-08 01:03发布

Im working in MVC 5.2 .NET 4.5:

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?

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

Thank you.

1条回答
来,给爷笑一个
2楼-- · 2019-09-08 02:09

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

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>
查看更多
登录 后发表回答