惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - a-peng

My post test IE inline edit how to make hidden element actually hide EntityFramework4.1 Mapping Asp.Net Mvc 3.0 Windbg IOC与AOP Custom Date and Time Format Strings group by Year(CreatedDate), Month(CreatedDate) 用sql, entity sql (linq表达式好像挺复杂) asp.net life cycle OH MY GOD! 我的后台页面都被IE可缓存了。。。 编译器错误消息: 类型“System.Data.Objects.DataClasses.EntityObject”在未被引用的程序集中定义。 让IFrame自适应高度 让IE8使用IE7兼容模式运行 - a-peng - 博客园 Visual Studio 2008 Html Designer无法加载 修改SQLServer2008数据表无法提交 jQuery plugin LazyForm定制您的CheckBox Radio和Select [转载] [翻译]在ASP.NET MVC中使用TDD与依赖注入 Asp.Net Mvc使用Ajax.BeginForm上传文件Request.Files始终为empty 太疯狂了:Teleport Pro......It's incredible.
Asp.Net Mvc Ajax偏方
a-peng · 2009-06-10 · via 博客园 - a-peng

问题描述:

使用Html.DropDownList显示产品类别下拉框,当选择产品类别后,在下方局部刷新显示对应的产品列表。

假设:如果是在Asp.Net WebForm

  1. 我想很多人会立即想到放个<asp:DropDownList />控件显示产品类别,在下方放个<asp:Repeater />控件显示产品列表。让DropDownList自动回发,在后台去绑定数据。不过这样无法局部刷新?使用<asp:UpdatePanel />包装下。

假设不成立:现在是在Asp.Net Mvc

  1. 我们先演示一个在Asp.Net Mvc中使用Ajax的简单事例

    1. 创建一个用户控件:ViewUserControl1.ascx代码如下

    1. 在HomeController中添加对应的Action代码如下

        

  1. Index.aspx代码如下


运行如下图

点击刷新如下图

刷新结束如下图

2、Ajax扩展中为什么没有Ajax.DropDownList呢?
没有已经是事实,我们得解决问题才行啊?怎么办?没思路。从上面的Demo里找找思路啊,看它是怎么做的,咱们模拟一个。

    查看Html源代码如下

    <a href="/Home/ViewUserControl1" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'loading', updateTargetId: 'ajaxResult' });">刷新</a>

    高兴了吗?开心了吗?onclick后面的东东,我们不是可以直接使用了。

  1. 好现在我们就来模拟

    1. 修改ViewUserControl1.ascx代码如下

  1. 修改HomeController中的ViewUserControl对应的Action代码如下

  1. 修改Index.aspx页面代码如下

运行如下图

不过在Firefox下出错如下

进入错误代码行

Sys.Mvc.AsyncHyperlink.handleClick(anchor, new Sys.UI.DomEvent(event), ajaxOptions);

这里的event我们未定义

改进下JavaScript代码