CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: HTML

Implement AJAX in MVC (the View)

608 Views
Copy Code Show/Hide Line Numbers
// The view: Index.aspx
 
<!-- the non-AJAX form to filter the list -->
<% using (Html.BeginForm()) { %>
    <fieldset>
    <legend>Search</legend>
    <input name="SearchTerm" />
    <input type="submit" value="Go" />
    </fieldset>
<% } %>
 
<!-- the AJAX form to filter the list -->
<script src="/Scripts/MicrosoftAjax.js" 
    type="text/javascript"></script> 
<script src="/Scripts/MicrosoftMvcAjax.js" 
    type="text/javascript"></script>
 
<% using (Ajax.BeginForm("Index2", 
    new AjaxOptions { UpdateTargetId = "results" })) { %>
    <fieldset>
    <legend>Search</legend>
    <input name="SearchTerm" />
    <input type="submit" value="Go" />
    </fieldset>
<% } %>
 
<!-- render the partial inside the view -->
<div id="results">
    <% Html.RenderPartial("Search", Model); %>
</div>
 
// The partial: Search.ascx (a default LIST 
// T4 template, nothing special/custom)
by Jerry Nixon
  March 05, 2010 @ 9:32am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate