Sys.ArgumentUndefinedException:值不能为未定义 [英] Sys.ArgumentUndefinedException: Value cannot be undefined
问题描述
我开发的asp.net mvc框架测试一些Ajax的东西。
不过,我得到异常如下。
任何人有问题都喜欢我?
Sys.ArgumentUndefinedException:值不能取消定义
和我的源$ C $ c是这个样子。
< ASP:内容ID =indexContentContentPlaceHolderID =日程地址搜索Maincontent=服务器><脚本SRC =../../脚本/ jQuery的-1.2.6.js的TYPE =文/ JavaScript的>< / SCRIPT>
<脚本SRC =../../脚本/ MicrosoftAjax.debug.js类型=文/ JavaScript的>< / SCRIPT>
<脚本SRC =../../脚本/ MicrosoftMvcAjax.debug.js类型=文/ JavaScript的>< / SCRIPT><脚本类型=文/ JavaScript的>
VAR MyView的; $(页面加载); 功能页面加载(){
MyView的= $创建(Sys.UI.DataView,{},{},{} $获得(ajaxResult));
$(#callAjaxButton),单击(callActionMethod)。
} 功能callActionMethod(){
$ .getJSON(/首页/ GetCategories,bindData);
} 功能bindData(数据){
myView.set_data(数据);
}< / SCRIPT><输入类型=按钮ID =callAjaxButtonVALUE =AjaxCall的/>< DIV ID =ajaxResult>< / DIV>< / ASP:内容>
从您提供有一对夫妇的事情要考虑的片段:
-
您缺少一个脚本参考<一个href=\"http://www.microsoft.com/Downloads/details.aspx?FamilyID=5c7df430-1c34-40d2-b6ec-81353b5fcf2e&displaylang=en\"相对=nofollow>微软ASP.NET AJAX 2.0的模板Visual Studio 2008的。
-
您正在使用jQuery的的document.ready 功能(只要提出在DOM随时可以查询及操纵),而不是<一个href=\"http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys/ApplicationClass/SysApplicationInitEvent.aspx\"相对=nofollow> System.Application.init 事件(所有的脚本已经被加载后提出,但在创建对象之前)。
你可以试试这个,看看它是否为你的作品:
&LT;脚本SRC =../../脚本/ jQuery的-1.2.6.js的TYPE =文/ JavaScript的&GT;&LT; / SCRIPT&GT;
&LT;脚本SRC =../../脚本/ MicrosoftAjax.debug.js类型=文/ JavaScript的&GT;&LT; / SCRIPT&GT;
&LT;脚本SRC =../../脚本/ MicrosoftMvcAjax.debug.js类型=文/ JavaScript的&GT;&LT; / SCRIPT&GT;
&LT;脚本SRC =../../脚本/ MicrosoftAjaxTemplates.debug.js类型=文/ JavaScript的&GT;&LT; / SCRIPT&GT;&LT;脚本类型=文/ JavaScript的&GT;
VAR MyView的; Sys.Application.add_init(页面加载); 功能页面加载(){
MyView的= $创建(Sys.UI.DataView,{},{},{} $获得(ajaxResult));
$(#callAjaxButton),单击(callActionMethod)。
} 功能callActionMethod(){
$ .getJSON(/首页/ GetCategories,bindData);
} 功能bindData(数据){
myView.set_data(数据);
}&LT; / SCRIPT&GT;&LT;输入类型=按钮ID =callAjaxButtonVALUE =AjaxCall的/&GT;
&LT; DIV ID =ajaxResult&GT;&LT; / DIV&GT;
写了一个漂亮的斯科特Hanselman的://www.hanselman。 COM /博客/ jQueryToShipWithASPNETMVCAndVisualStudio.aspx相对=nofollow>帖子关于这个问题的。
I am developing some ajax stuff on asp.net mvc framework beta.
but,I got exception as following. Anyone has problem like me?
Sys.ArgumentUndefinedException: Value cannot be undefined.
and my source code is like this.
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<script src="../../Scripts/jquery-1.2.6.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script type="text/javascript">
var myView;
$(pageLoad);
function pageLoad() {
myView = $create(Sys.UI.DataView, {}, {}, {}, $get("ajaxResult"));
$("#callAjaxButton").click(callActionMethod);
}
function callActionMethod() {
$.getJSON("/Home/GetCategories", bindData);
}
function bindData(data) {
myView.set_data(data);
}
</script>
<input type="button" id="callAjaxButton" value="ajaxCall" />
<div id="ajaxResult"></div>
</asp:Content>
From the snippet you provided there are a couple of things to consider:
You are missing a script reference to the Microsoft ASP.NET 2.0 AJAX Templates for Visual Studio 2008.
You are using the jquery's document.ready function (raised whenever the DOM is ready to be traversed and manipulated) instead of the System.Application.init event (raised after all scripts have been loaded but before objects are created).
Can you try this to see if it works for you:
<script src="../../Scripts/jquery-1.2.6.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjaxTemplates.debug.js" type="text/javascript"></script>
<script type="text/javascript">
var myView;
Sys.Application.add_init(pageLoad);
function pageLoad() {
myView = $create(Sys.UI.DataView, {}, {}, {}, $get("ajaxResult"));
$("#callAjaxButton").click(callActionMethod);
}
function callActionMethod() {
$.getJSON("/Home/GetCategories", bindData);
}
function bindData(data) {
myView.set_data(data);
}
</script>
<input type="button" id="callAjaxButton" value="ajaxCall" />
<div id="ajaxResult"></div>
Scott Hanselman has written a nice post on this subject.
这篇关于Sys.ArgumentUndefinedException:值不能为未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!