您的位置:首页 > 编程语言 > ASP

ASP.NET-ajax.BeginForm使用02

2016-03-24 09:10 495 查看
using就已经是引入了ajax了,其实是操作了js文件,所以这个是全局的,using 的{}没有必要把所有的东西都扩住
@using (Ajax.BeginForm(

new AjaxOptions()

{

HttpMethod = "post",

Url = @Url.Action("ajax", "Home"),

InsertionMode = InsertionMode.Replace,

UpdateTargetId = "pid",

LoadingElementId = "loding",

LoadingElementDuration = 5000

}))

{

<input type="submit" value="点击返回ajax内容" />

}

[/code]
@using (Html.BeginForm("Person", "Home", new { fk = "this is fk test" }, FormMethod.Post))

[/code]
fk是后台已经定义的变量名,可以从前台把变量名传回去

注意

1.需要引用jquery.unobtrusive-ajax.js

2.需要在引用jquery后引用jquery.unobtrusive-ajax.js

3.config中需要有(这个MVC4,MVC5默认就是有的)

<add key="ClientValidationEnabled" value="true" />

<add key="UnobtrusiveJavaScriptEnabled" value="true" />

Confirm等效于javascript中的return confirm(msg),在点击该链接时先提示需要确认的信息。
HttpMethod指定使用Get或者是Post方式发送Http请求
InsertMode指定使用哪一种方式在指定的UpdateTargetId元素更新数据,可以有三种方式: "InsertAfter", "InsertBefore", or "Replace" 。默认为:Replace
LoadingElementDuration Loading元素显示的时间
LoadingElementId 可以指定在Http请求期间显示的Loading元素
OnBegin 在Http请求之前执行的javascript方法
OnComplete 在Http请求结束时执行的方法
OnFailure 在Http请求失败时执行的方法
OnSuccess 在Http请求成功时执行的方法
UpdateTargetId Http请求更新的页面元素
Url Http请求的Url


onBegin里面的函数是直接写就可以执行的



当然也可以写jquery的代码

来自为知笔记(Wiz)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: