问题
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:
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>
来源:https://stackoverflow.com/questions/27531320/input-mask-mvc-unmask-in-controller