Search code examples
asp.netajaxasp.net-mvc-3ajax.beginformformcollection

AJAX.BeginForm send empty FormCollection list to MVC Controller


i have a very simple code:

@using (Ajax.BeginForm("SearchAccount", "Account", new AjaxOptions { UpdateTargetId = "SearchResults", HttpMethod = "Get", InsertionMode = InsertionMode.Replace })) 
    {
        <fieldset>
            <input id="txtSearchBox" name="SearchString" type="text"  />
        </fieldset>
        <input type="submit" value="Search"  />
    }

and on controller side i have following code

public PartialViewResult SearchAccount(FormCollection formCollection)
    {
        try
        {
            string SearchString = formCollection["SearchString"];
            List<Moovers.DAL.Account> Accounts = Moovers.BL.Account.SearchAccount(SearchString);

            return PartialView("_AccountSearchResult", Accounts);        
        }
        catch (Exception ex)
        {
            throw;
        }

    }

the problem is "FormCollection", which is empty. What could be the possible reason ?


Solution

  • This is because you're using "GET" as your method.

    See https://stackoverflow.com/a/2265210/120955