我们如何防止MVC3中的“提交"按钮动作? [英] How can We prevent the Submit button action in MVC3?
问题描述
我在mvc34剃刀视图中遇到了提交按钮的问题.我在jQuery中动态添加了一行到webgrid,其中包含一个提交按钮以将行数据插入db.我想验证行的文本框是否空弹出一个警报并停止操作.当我试图这样写的时候
I have faced a problem with the submit button in mvc34 razor view.I have added a row dynamically in jQuery to webgrid which contains one submit button to insert the row data in db.I want to validate the textbox of the row if empty pop up a alert and stop the action. When I tried to write like this
$('#btnInsert').click(function()
{
if ($('#tbStudentName').val() == '') {
alert('Please enetre!');
return false;
}
});
jQuery根本不会触发此事件.我们可以像上面那样在jQuery中调用动态创建的提交按钮客户端单击事件吗?我是这样写的
This Event is not at all firing in jQuery.Can we call the dynamically created submit button client click event in jQuery like above? I have written like this
function InsertClick(button) {
if ($('#tbStudentName').val() == '') {
alert('Please enetre!');
return false;
}
}
但仍会触发Controller Side FormAction方法.
but still the Controller Side FormAction method is firing. Could any one tell me the solution to prevent the action in server side?
推荐答案
(' #btnInsert').click(函数() { 如果(
('#btnInsert').click(function() { if (
(' ' ' 请渗透!'); 返回 假; } });
('#tbStudentName').val() == '') { alert('Please enetre!'); return false; } });
jQuery根本不会触发此事件.我们可以像上面那样在jQuery中调用动态创建的提交按钮客户端单击事件吗?我是这样写的
This Event is not at all firing in jQuery.Can we call the dynamically created submit button client click event in jQuery like above? I have written like this
function InsertClick(button) {
if (
(' ' ' 请渗透!'); 返回 假; } }
('#tbStudentName').val() == '') { alert('Please enetre!'); return false; } }
但仍会触发Controller Side FormAction方法.谁能告诉我解决方案,以防止在服务器端执行此操作?
but still the Controller Side FormAction method is firing. Could any one tell me the solution to prevent the action in server side?
这篇关于我们如何防止MVC3中的“提交"按钮动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!