MVC 3剃须刀 - Ajax.BeginForm的onSuccess [英] MVC 3 Razor - Ajax.BeginForm OnSuccess
问题描述
我是新来的MVC,我想后,我提出我的表格来更新我的网页;但它不工作。我只是想隐瞒的形式,并显示一个div的onSuccess的内容。
I'm new to MVC and I'm trying to update my page after I submit my form; but it's not working. I'm only trying to hide the form, and show the contents of a div OnSuccess.
我的code是:
<script type="text/javascript">
$(document).ready(function () {
$('#confirmation').hide();
});
function MessageConfirmation() {
$('#confirmation').show('slow');
$('#contactForm').hide('slow');
}
</script>
@using (Ajax.BeginForm("Index", new AjaxOptions { OnSuccess = "MessageConfirmation" }))
{
<fieldset id="contactForm">
<legend>Message</legend>
<p>
@Html.Label("Email", "Email"): @Html.TextBox("Email")
</p>
<p>
@Html.Label("Subject", "Subject"): @Html.TextBox("Subject")
</p>
<p>
@Html.Label("Message", "Message"): @Html.TextArea("Message")
</p>
<p>
<input type="submit" value="Send" />
</p>
</fieldset>
<p id="confirmation" onclick="MessageConfirmation()">
Thanks!!!
</p>
}
任何替代解决方案/想法是最欢迎的。
Any alternate solutions / ideas are most welcome.
在此先感谢!
推荐答案
不工作的是一个问题的描述是更适合的人不知道/关心如何计算机的工作原理,而不是软件开发。软件开发人员通常描述precisely他们遇到的问题。他们张贴他们有确切的错误消息/异常堆栈跟踪。
Not working is a problem description that's more adapted to people that don't know/care about how computer works and not software developers. Software developers usually describe precisely the problem they are having. They post the exact error message/exception stack trace they are having.
这是说你所要求的替代解决方案,这里是我的:不使用任何 MS阿贾克斯*佣工
,使用jQuery直接和不显眼,像这样
This being said you are asking for alternative solutions, here's mine: don't use any MS Ajax.* helpers
, use jquery directly and unobtrusively, like this
<script type="text/javascript">
$(function () {
$('#confirmation').hide();
$('form').submit(function() {
$('#confirmation').show('slow');
$(this).hide('slow');
return false;
});
});
</script>
@using (Html.BeginForm())
{
<fieldset id="contactForm">
<legend>Message</legend>
<p>
@Html.Label("Email", "Email"):
@Html.TextBox("Email")
</p>
<p>
@Html.Label("Subject", "Subject"):
@Html.TextBox("Subject")
</p>
<p>
@Html.Label("Message", "Message"):
@Html.TextArea("Message")
</p>
<p>
<input type="submit" value="Send" />
</p>
</fieldset>
}
<p id="confirmation">
Thanks!!!
</p>
请注意确认
段已经从外在的形式。
Notice how the confirmation
paragraph has been externalized from the form.
这篇关于MVC 3剃须刀 - Ajax.BeginForm的onSuccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!