ASP.NET MVC - AjaxContext
我尝试检查 ASP.NET-MVC 使用的 AjaxContext,例如 Ajax Actionlinks 及其 onSucces、onComplete 等客户端函数。 但我不太明白...这东西的文档在哪里?
有人知道当我处于 onSuccess 或 onComplete javascript 事件中时如何获取“target”或“srcElement”(e.target 或 window.event.srcElement)吗?
<%=Ajax.ActionLink(
"LinkText", "Action", New With {.Controller = "ControllerName"},
New AjaxOptions With {
.UpdateTargetId = "divElement",
.OnSuccess = "function(ajaxContext) {console.log(ajaxContext);}"
}) %>
其结果是:
<a
href="/Popout/ApplicationCodePopout"
onclick="Sys.Mvc.AsyncHyperlink.handleClick(
this, new Sys.UI.DomEvent(event),
{
insertionMode: Sys.Mvc.InsertionMode.replace,
updateTargetId: 'divElement',
onSuccess: Function.createDelegate(this,
function(ajaxContext) {console.log(ajaxContext);}
)
}
);"
>LinkText</a>
I've tried to inspect the AjaxContext that ASP.NET-MVC uses on for instance Ajax Actionlinks and their onSucces, onComplete etc. clientside functions. But I don't understand very much of it... Where is the documentation on this thing?
Does anybody know how to I get the 'target' or 'srcElement' (e.target or window.event.srcElement) when I am in a onSuccess or onComplete javascript event?
<%=Ajax.ActionLink(
"LinkText", "Action", New With {.Controller = "ControllerName"},
New AjaxOptions With {
.UpdateTargetId = "divElement",
.OnSuccess = "function(ajaxContext) {console.log(ajaxContext);}"
}) %>
Which results in:
<a
href="/Popout/ApplicationCodePopout"
onclick="Sys.Mvc.AsyncHyperlink.handleClick(
this, new Sys.UI.DomEvent(event),
{
insertionMode: Sys.Mvc.InsertionMode.replace,
updateTargetId: 'divElement',
onSuccess: Function.createDelegate(this,
function(ajaxContext) {console.log(ajaxContext);}
)
}
);"
>LinkText</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 onSuccess 方法更改为:(
注意调试器关键字)
然后您可以使用 VS2008 闯入它(假设使用 IE,如果您使用 Firefox,则安装 Firebug 正如 Jake 所说),然后您可以使用快速监视窗口(在 VS 中或 Firebug 等中的等效窗口)来查看对象及其属性/方法 ?
至于一些文档,请查看 此链接查看代码注释,以及这篇文章了解更多信息。
You could change the onSuccess method to this:
(Note the debugger keyword)
Then you can break into it using VS2008 (assuming IE, if you're using Firefox, then install Firebug as Jake said) and then you can use the quick watch window (in VS or equivalent in Firebug etc) to view the object and it's properties/ methods etc.
As for some documentation, check out this link to see the code comments, and this article for some more information.
好的,您需要安装 Firebug (如果您还没有安装,请立即安装:) 现在开始使用 console.log 在代码中帮助您了解每个对象具有哪些可用属性和功能。 尝试输入 console.log(document) - 您可以在控制台窗口的文本框(>> 旁边)中执行此操作。 请注意如何单击控制台中的链接来查询并查看对象具有哪些可用属性和功能。
Okay so you need to get Firebug installed (If you havnot already done so do it now :) Now start using console.log in your code to help you find out what properties and functions each object has available. Try typing in console.log(document) - You can do this in the Console window in the textbox (next to the >>>). Notice how you can click on the links in the console to interigate and see what properties and functions the object has available.
我还建议阅读jQuery 实践。 我读过的最好的科技书籍之一! 一旦您阅读了本文,您将能够开始编写自己的 jQuery 代码,而不必担心使用为您输出 javascript 的服务器端包装库:)
看看
http://www.scribd.com/doc/8635225/jQuery-in-行动
I would also recommend reading jQuery in action. One of the best tech books I have ever read! Once you read that you will be able to start writing your own jQuery code and not have to worry about using a server side wrapper library that spits out javascript for you :)
Check it out
http://www.scribd.com/doc/8635225/jQuery-in-Action