0
我正在使用MVC3構建嚮導步驟演示應用程序,並使用剃鬚刀視圖引擎作爲初始級別。在MVC中使用Razor視圖進行驗證的問題
我遇到了驗證問題時隱藏&通過javascript顯示控件。
請看看我的代碼段按以下
<div class="editor-field">
@Html.EditorFor(model => model.CheckName2)
@Html.ValidationMessageFor(model => model.CheckName2)
</div>
我的JavaScript函數按下面,隱藏&表演上的一些條件
// attach nextStep button handler
$("#next-step").click(function() {
var $step = $(".wizard-step:visible"); // get current step
//check if URL2 is having any content
var val = $("#URL2").val();
if (val == "") {
$("#CheckName2").hide();
//want to remove validation here
}
else {
$("#CheckName2").show();
//want to add validation here
}
var validator = $("form").validate(); // obtain validator
var anyError = false;
$step.find("input").each(function() {
if (!validator.element(this)) { // validate every input element inside this step
anyError = true;
}
});
if (anyError)
return false; // exit if any error found
我怎麼能在這裏辦理驗證?
在此先感謝。
我有問題與form.validation部分更新的JavaScript代碼,請看看,並建議我一些解決方案 – 2012-01-07 13:08:50