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

Implement AJAX in MVC (the Controller)

510 Views
Copy Code Show/Hide Line Numbers
//
// GlossaryController.cs
 
public ActionResult Index()
{
    return View(Models.Term.SelectAll());
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection collection)
{
    // used by non-AJAX form 
    string _SearchTerm;
    _SearchTerm = collection["SearchTerm"];
    // don't indicate the partial here
    // the view will call it
    return View(Models.Term
         .Where(x => x.Term.Contians(_SearchTerm)));
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index2(FormCollection collection)
{
    // used by AJAX form 
    string _SearchTerm;
    _SearchTerm = collection["SearchTerm"];
    // you must indicate the partial here
    // it's all you want to render
    return View("Search", Models.Term
         .Where(x => x.Term.Contians(_SearchTerm)));
}
by Jerry Nixon
  March 05, 2010 @ 9:29am
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