我需要验证我的 ASP MVC3 视图中的一些字段,并尝试使用 jQuery 来执行此操作。jQuery.val()
方法可以很好地从输入字段中提取 、 和 ,但是该accountNumber
字段refNumber
的值始终为 。ownerMaster
agentId
""
我一遍又一遍地查看代码中的拼写错误,但没有找到。希望另一双眼睛能解决问题。
仅供参考 - 如果我将下面的.val()
on更改为 hide 方法有效并且该字段消失,这意味着我输入了正确的选择器。$('#AgentId').val()
.hide()
jQuery
function ValidateFields(transactionType) {
var msg = "";
var refNumber = $('#RefNumber').val();
var ownerMaster = $('#OwnerMasterAgentId').val();
var accountNumber = $('#AccountNumber').val();
var agentId = $('#AgentId').val(); //When the agentId variable an selector + val() are
//evaluated here both have a value of ""
ASP MVC 剃刀
<div class="M-editor-label">
@Html.LabelFor(model => model.RefNumber)
<span class="alwaysReq"> @Html.Raw("*")</span>
</div>
<div class="M-editor-field">
@Html.TextBoxFor(model => model.RefNumber, new { maxlength = 9, @class = "staticData" })
</div>
<div class="M-editor-label">
@Html.LabelFor(model => model.OwnerMasterAgentId)
<span class="req">@Html.Raw("*")</span>
</div>
<div class="M-editor-field">
@Html.TextBoxFor(model => model.OwnerMasterAgentId, new { maxlength = 8, @class="staticData" })
</div>
<div class="M-editor-label">
@Html.LabelFor(model => model.AccountNumber)
<span class="req">@Html.Raw("*")</span>
</div>
<div class="M-editor-field">
@Html.TextBoxFor(model => model.AccountNumber, new { maxlength = 17 })
</div>
<div class="M-editor-label">
@Html.LabelFor(model => model.AgentId)
<span class="req">@Html.Raw("*")</span>
</div>
<div class="M-editor-field">
@Html.TextBoxFor(model => model.AgentId, new { maxlength = 8 })
</div>
HTML
<div class="M-editor-label">
<label for="RefNumber">Reference Number</label>
<span class="alwaysReq" style="display: inline;"> *</span>
</div>
<div class="M-editor-field">
<input class="staticData" id="RefNumber" maxlength="9" name="RefNumber" type="text" value="">
</div>
<div class="M-editor-label">
<label for="OwnerMasterAgentId">Owner Master Agent Id</label>
<span class="req" style="display: inline;">*</span>
</div>
<div class="M-editor-field">
<input class="staticData" id="OwnerMasterAgentId" maxlength="8" name="OwnerMasterAgentId" type="text" value="">
</div
<div class="M-editor-label">
<label for="AccountNumber">Account Number</label>
<span class="req" style="display: inline;">*</span>
</div>
<div class="M-editor-field">
<input id="AccountNumber" maxlength="17" name="AccountNumber" type="text" value="">
</div>
<div class="M-validator-field">
<span class="field-validation-valid" data-valmsg-for="AccountNumber" data-valmsg-replace="true" style="display: none;"></span>
</div>
<div class="M-editor-label">
<label for="AgentId">Agent ID</label>
<span class="req" style="display: inline;">*</span>
</div>
<div class="M-editor-field">
<input id="AgentId" maxlength="8" name="AgentId" type="text" value="">
</div>