Asp.net mvc 关于MVC中选项卡中的验证
我有3个选项卡,这3个选项卡都有“提交”和“取消”按钮。当用户单击“提交”按钮时,它会自动切换到激活验证的选项卡,我如何使用下面的代码实现此功能Asp.net mvc 关于MVC中选项卡中的验证,asp.net-mvc,asp.net-mvc-3,jquery,Asp.net Mvc,Asp.net Mvc 3,Jquery,我有3个选项卡,这3个选项卡都有“提交”和“取消”按钮。当用户单击“提交”按钮时,它会自动切换到激活验证的选项卡,我如何使用下面的代码实现此功能 部分视图:Service.cs.html <script type="text/javascript"> $(document.body).ready(function () { getService("Test1"); }); function getService(serviceMenuId)
部分视图:Service.cs.html
<script type="text/javascript">
$(document.body).ready(function () {
getService("Test1");
});
function getService(serviceMenuId) {
if (serviceMenuId != undefined && serviceMenuId != '') {
jQuery("div#menubar li").each(function () {
var $li = jQuery(this);
$li.removeClass('sel');
});
document.getElementById(serviceMenuId).className = "sel";
}
$('div#Test1').hide();
$('div#Test2').hide();
$('div#Test3').hide();
$("div#" + serviceMenuId).show();
}
</script>
@using (Html.BeginForm())
{
<div id="Test1" style="position:relative">@{Html.RenderPartial("Test1", Model);}</div>
<div id="Test2" style="position:relative">@{Html.RenderPartial("Test2", Model);}</div>
<div id="Test3" style="position:relative">@{Html.RenderPartial("Test3", Model);}</div>
<div id="saveCancelButton" class="as-ext-form-button-div" style="margin-top: 20px;">
<button title="Click here to save" id="saveData" type="submit" onclick="return attributesValid();">Save</button>
</div>
}
$(document.body).ready(函数(){
getService(“Test1”);
});
函数getService(serviceMenuId){
如果(serviceMenuId!=未定义&&serviceMenuId!=''){
jQuery(“div#menubar li”)。每个(函数(){
var$li=jQuery(本);
$li.removeClass('sel');
});
document.getElementById(serviceMenuId).className=“sel”;
}
$('div#Test1').hide();
$('div#Test2').hide();
$('div#Test3').hide();
$(“div#“+serviceMenuId).show();
}
@使用(Html.BeginForm())
{
@{Html.RenderPartial(“Test1”,Model);}
@{Html.RenderPartial(“Test2”,Model);}
@{Html.RenderPartial(“Test3”,Model);}
拯救
}
我不确定它是否有帮助,但您可以尝试对无效数据使用焦点:
$("#saveData").click(function() {
if ($("form").valid())
{
alert("Valid!");
}
else
{
validator.focusInvalid();
}
return false;
});