I seem to have a problem with getting MVC to fill in my custom model parameter when called through GET instead of POST.
I have a JavaScript snippet that calls into an action like so:
$.getJSON('<%= Url.Action("DoSearch") %>' + location.search,
function(data) {
if (data.Result == "OK") {
location.href = location.href;
}
});
What it does, is basically call a separate action, passing it the same querystrings as the calling page. Then if the result is "OK", it refreshes the current page.
The action is defined like the following:
public ActionResult DoSearch(SearchParameters searchParameters)
The model is:
public class SearchParameters
{
public string Query;
...
}
Calling URL (verified with firebug) is like /DoSearch?Query=some+query
. (also tried /DoSearch?searchParameters.Query=some+query
with no success)
No matter what I tried, my parameter always comes up as empty (not null, just all of the parameters being initialized to their default values)
If I define the action like this instead:
public ActionResult DoSearch(string Query, ...)
Then my parameters get filled correctly. Not with the model however.
I assume:
a) either populating the object model doesn't work for GET requests.
b) I'm doing something wrong
Any ideas? Thanks.