Thoughts from Dan Miser RSS 2.0
 Sunday, May 31, 2009
Given a set up like this (where ExpenseSummaryData returns some arbitrary HTML fragment) :

<%using (Ajax.BeginForm("ExpenseSummaryData", new AjaxOptions { UpdateTargetId = "result" })) { %>
    <label for="startDate">Start Date:</label>
    <%= Html.TextBox("startDate") %>
    <br />
    <label for="endDate">End Date:</label>
    <%= Html.TextBox("endDate")%>
    <br />
    <input type="submit"/>
    <br />
    <span id="result"/>
<% } %>

If that is all your page does, you will notice that you get taken to a new page when pressing Submit. The data on the new page is the HTML fragment returned by the AJAX call, but that's all it contains (e.g. no master page), and it's clearly not replacing the result span.

The reason for this is that I forgot to add the following lines to the <head> section in the original page:


    <script src='<%=ResolveUrl("~/Content/js/MicrosoftAjax.debug.js")%>' type="text/javascript"></script>
    <script src='<%=ResolveUrl("~/Content/js/MicrosoftMvcAjax.debug.js")%>' type="text/javascript"></script>

After adding those declarations in, the content in the span tag is properly updated and it looks like a real AJAX call.

Sunday, May 31, 2009 10:38:24 AM (Central Standard Time, UTC-06:00)  #    Comments [0] -
.NET | ASP.NET MVC
Comments are closed.
Navigation
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Dan Miser
Sign In
Statistics
Total Posts: 339
This Year: 5
This Month: 0
This Week: 0
Comments: 618
All Content © 2010, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)