在mvc3中提交表单后,如何使用ajax和jquery显示成功消息 [英] how to show success message with ajax and jquery after submission of form in mvc3

查看:63
本文介绍了在mvc3中提交表单后,如何使用ajax和jquery显示成功消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mvc3中提交表单后,如何使用ajax和jquery显示成功消息. 我是MVC3的新手,以前从未使用过Ajax,因此我可以参考的任何一个电话解决方案或示例都可以使用...

how to show success message with ajax and jquery after submission of form in mvc3..
I am new in MVC3 and i never used ajax before so can any one tel me solution or example which i can refer...

推荐答案

 function FUNCTIONNAME() {


.ajax({ 类型:" , url:" , 数据:" , contentType:" , dataType:" , 完成:功能(){ }, 成功:功能(msg){ alert(" 功能(msg){ alert(" + msg.d.toString()); } }); }
.ajax({ type: "POST", url: "YOUR METHOD NAME WHICH IS CALLED", data: "{PARAMETER VALUES TO BE PASSED}", contentType: "application/json; charset=utf-8", dataType: "json", complete: function () { }, success: function (msg) { alert("YOUR SUCCESS MESSAGE HERE"); }, error: function (msg) { alert("Error " + msg.d.toString()); } }); }


Hello Vishal,

您应该将Ajax文学作品用作具有新功能的MVC3,可以使用Ajax.Beginform提交表单.

在您的视图中写以下内容

< script src ="@ Url.Content("〜/Scripts/jquery.unobtrusive-ajax.min.js)" type ="text/javascript"></script>

Hello Vishal,

you should be use Ajax Literary as MVC3 having new feature,you can submit your form by using Ajax.Beginform.

write following stuff in your view

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>


br mode ="hold"/>
@using(Ajax.BeginForm("Sample",new AjaxOptions {UpdateTargetId ="targetId",HttpMethod ="Post"}))
{

br mode="hold" />
@using (Ajax.BeginForm("Sample", new AjaxOptions { UpdateTargetId = "targetId", HttpMethod = "Post"}))
{






}

它将在控制器中执行采样"操作,并将结果附加到"targetId" div
UpdateTargetId 属性指定了要在页面上显示或更新结果的位置.

\\控制器的东西
[httpPost]
公共字符串Sample()
{
返回"AjaxBeginForm调用的操作";
}

这样,您可以使用Ajax.BeginForm方法提交页面,而无需刷新整个页面.


}

it will "Sample" action in controller and append your result in "targetId" div
UpdateTargetId attribute specified where you want to display or update your result on page.

\\controller stuff
[httpPost]
public string Sample()
{
return "Action Called by AjaxBeginForm";
}

In this way you can submit you page by using Ajax.BeginForm method without refreshing your whole page.


这篇关于在mvc3中提交表单后,如何使用ajax和jquery显示成功消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆