Error with Ajax.Beginform on ASP.NET MVC Page

旧城冷巷雨未停 提交于 2019-12-11 05:44:55

问题


I am using Ajaxy Call to load the partial view. It is working fine in Firefox and IE without in Debug Mode. But in Debug mode, I am getting the follwoing error:

Error: 'Sys' is undefined

Ajaxy call Code:

 <% using (Ajax.BeginForm("SearchResults", new AjaxOptions { UpdateTargetId = "divLoadSearchResults" } ))
{%>

HTML View Source corresponding to this:

<form action="/Home/SearchResults" method="post" onclick="***Sys.***Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));" onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'divLoadSearchResults' });">

I am using MVC RC2 framework. Anyone have similar problems with RC2?

If it is not in Debug mode, it is working fine. Again, if i run it using Debug mode or CTRL+F5, it shows up the error.

Appreciate your responses.


回答1:


Sounds like it is not loading the MicrosoftMvcAjax.js or MicrosoftAjax.js files when in debug mode. Check where you are including these files and make sure that there aren't any conditionals that would exclude it. If you are using the content delivery network to load it when not debugging, make sure that the paths in the alternate loads when debugging are correct.

Ex:

<% if (debug) { %>
     <script type="text/javascript"
             src="<%= Url.Content( "~/scripts/MicrosoftAjax.debug.js" ) %>">
      </script>
      <script type="text/javascript"
              src="<%= Url.Content( "~/scripts/MicrosoftMvcAjax.debug.js" ) %>">
      </script>
<% }
   else { %>
      <script type="text/javascript"
              src="http://ajax.microsoft.com/ajax/mvc/1.0/MicrosoftAjax.js">
      </script>
      <script type="text/javascript"
              src="http://ajax.microsoft.com/ajax/mvc/1.0/MicrosoftMvcAjax.js">
      </script>
<% } %>


来源:https://stackoverflow.com/questions/2405966/error-with-ajax-beginform-on-asp-net-mvc-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!