我有一个使用 Ajax 发送的表单。
有一个带掩码的字段,其值如下所示:(此字段是动态添加的)
(011) 1111-1111
我有一个删除掩码的 beforeSend 回调函数。
我可以在发送表单之前看到该字段:
01111111111
但是在我的控制器中,我得到的值就好像我没有移除面具一样。无法理解为什么!
形式
@using (Ajax.BeginForm("opImportFile", "Operacao", new AjaxOptions { HttpMethod = "POST", OnBegin = "validation", OnSuccess = "LimparCampos", OnFailure = "LimparCampos" }, new { id = "formUpdStoringSettings" }))
{
<fieldset>
<legend>Importação - Arquivo</legend>
<!-- <h2><a href="#" id="AddAbsPath" class="editBtn" onclick="addArmazenamento();" style="font-size:12px; color:#E17009 !important;"> Adicionar</a></h2> -->
<table id="tblArmazenamento">
<tr id="@element">
<td>@Html.Hidden("idCaminhoRepositorio_" + element)
@Html.TextBox("caminhorepositorio_" + element, "", new { @class = "validate[required] smallField limpar", disabled = "disabled" })
@Html.Hidden("caminhoRepositorio_" + element, "", new { @class = "validate[required] smallField limpar"})</td>
<td><a href="#" id="editPath" class="editBtn" onclick="FileTree()"> Localizar</a>
<a href="#" id="RemAbsPath_@element" class="editBtn" onclick="removeArmazenamento(@element);" style="color:red !important;"> Remover</a>
</td>
</tr>
<tr><td colspan="2">@Html.DropDownListFor(m => m.tipo, new SelectList(Model.tipo, "idTipo", "nomeTipo"), "Escolha um Tipo", new { @class = "validate[required] smallField" })</td></tr>
<tr><td colspan="2"><br /></td></tr>
</table><br />
<input type="submit" value="Importar" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only button-link" />
</fieldset>
}
打回来
function validation() {
$('.mask').each(function (index) {
$(this).val($(this).val().replace('(', ''));
$(this).val($(this).val().replace(')', ''));
$(this).val($(this).val().replace(/-/g, ''));
$(this).val($(this).val().replace(/ /g, ''));
$(this).text($(this).val()); //Here I get an unmaked value
});
}
控制器
string[] indicesValues = form["group"].Split(','); //Here I am getting a masked value