asp.net-mvc – Asp.Net MVC Ajax.BeginForm没有通过Ajax提交
发布时间:2020-05-24 01:00:52 所属栏目:asp.Net 来源:互联网
导读:我的表格如下 div id=contact-form class=hidden title=Online Request Form @Using (Ajax.BeginForm(Contact, Main, Nothing, New AjaxOptions Wit
|
我的表格如下 <div id="contact-form" class="hidden" title="Online Request Form">
@Using (Ajax.BeginForm("Contact","Main",Nothing,New AjaxOptions With {.UpdateTargetId = "status",.HttpMethod = "post"},New With {.id = "contactUs"}))
@<div>
@Html.LabelFor(Function(m) m.Name)<br />
@Html.TextBoxFor(Function(m) m.Name)<br />
@Html.LabelFor(Function(m) m.Phone)<br />
@Html.TextBoxFor(Function(m) m.Phone)<br />
@Html.LabelFor(Function(m) m.Email)<br />
@Html.TextBoxFor(Function(m) m.Email)<br />
@Html.LabelFor(Function(m) m.Question)<br />
@Html.TextAreaFor(Function(m) m.Question)<br />
@Html.LabelFor(function(m) m.Security)<br />
@Html.TextBoxFor(Function(m) m.Security)<br />
<noscript>
<input type="submit" name="submit" value="Ok" />
</noscript>
@Html.ValidationSummary("Oops,please correct the errors.")<span id="status">@TempData("status")</span>
</div>
End Using
</div>
我在jQuery-UI模态窗口中打开它 <script>
$(function () {
// Open the modal dialog from the div.contact-us click event
$('#contact-us').click(function () {
$('#contact-form').dialog('open');
return false;
});
// Manage the modal dialog behavior.
$('#contact-form').dialog({
modal: true,autoOpen: false,buttons: {
Cancel: function () {
$(this).dialog('close');
},Ok: function () {
$('form#contactUs').trigger('submit');
}
}
});
});
</script>
当我点击“确定”按钮,它发布到相应的控制器,但它不是通过AJAX发布 ''# fix the StackOverflow code coloring issue.
<HttpPost()>
Function Contact(ByVal contactForm As Models.ContactForm) As ActionResult
ViewData("Testimonials") = Helpers.GetTestimonials
If ModelState.IsValid Then
''# Submit the email
TempData("status") = "Thank you,we will be in touch"
Else
''# Return False
TempData("status") = "Oops,please correct the errors."
End If
If Request.IsAjaxRequest Then
Return Content(TempData("status").ToString)
Else
Return View("Index")
End If
End Function
我究竟做错了什么?提交表单后,我的网址为http://example.com/Main/Contact,告诉我IsAjaxRequest = false 编辑 即使我不使用jquery-ui“ok”按钮,只需添加< input type =“submit”name =“submit”value =“Ok”/>以表格形式,没有Ajax的表单 解决方法你有jquery ajax脚本吗?我没有注意到这种行为:<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-5 – ASP.NET MVC中Controller的模型对象列表的
- asp.net-mvc – 如何在ASP.NET MVC w / VB.NET中添加id HTM
- asp.net – 角色提供程序是否按请求缓存?
- 尝试使用VS和IIS Express在本地设置HTTPS时出现连接重置错误
- asp.net – 如何将一个对象序列化为查询字符串格式?
- asp.net-mvc – 在ASP.NET MVC应用程序中记录用户活动
- ASP.NET – 从内容页面访问主页面元素
- 如何在ASP.NET MVC中使用JQuery调用控制器操作
- 如何在ASP.NET应用程序中使用jQuery捕获提交事件?
- asp.net-mvc – 异步使用ASP.NET MVC中的WebClient?
推荐文章
站长推荐
- 使用StateServer的ASP.NET会话混合(SCARY!)
- 如何在不使用角色的情况下使用ASP.NET WebAPI实现
- ASP.NET全球化:Culture =“auto”页面指令,中性
- asp.net – 在新的MVC4应用程序中获取UserId(int
- asp.net-mvc-3 – Html.RenderPartial和Ajax.Beg
- asp.net-core – 将命名空间添加到ASP.NET MVC 6
- asp.net-mvc-2 – MVC Html.TextBoxFor MaxLengt
- asp.net-mvc – ASP.NET MVC中的AntiForgeryToke
- asp.net-mvc – 具有点的窗体元素的MVC Controll
- ASP.Net MVC授权操作过滤器
热点阅读
