The answer to your question is definitely, "yes".
I've got one in front of me right now, so I'll try to abstract it out.
First, create a controller action that returns a JsonResult (rather than ActionResult). Other than its return type it's just like any other action, so you can send parameters, etc. The only thing that's really different is that you're going to return a JsonResult() object, setting its Data property and any other properties that you may need. Mine looks something like this (very pseudo-codish...):
public JsonResult GetList(int parentId)
{
var results = dataRepository.GetById(parentId);
return new JsonResult()
{
Data = results.ToArray();
};
}
Now, in your view, create a script that looks something like this. Note that this is jQuery syntax, so it may look a bit unusual if you're not familiar with it.
<script language="javascript" type="text/javascript">
// When the document is ready, start firing our AJAX
$(document).ready(function() {
// Bind a function to the "change" event of our drop-down list
$("#dropDownId").bind("change", function(e) {
updateList();
});
}
var retrieveData = function(path, parentId, fnHandleCallback) {
// Use the getJSON method to call our JsonResult action
$.getJSON(path, { parentId: parentId }, function(data) {
fnHandleCallback(data);
});
};
// The path parameter is our JSON controller action
function updateList() {
retrieveData("/Controller/GetList", $("#dropDownId").val(), handleResponse);
}
function handleResponse(data) {
// Ok, now we have the JSON data, we need to do something with it. I'm adding it to another dropdown.
$("#otherDropDownId > option").remove();
for (d in data)
{
var item = data[d];
$("#otherDropDownId").append("<option value=\"" + item.Value + "\">" + item.Text + "</option>");
}
}
</script>
<%= Html.DropDownList("dropDownId", new SelectList(new List<SelectListItem>())) %>
<%= Html.DropDownList("otherDropDownId", new SelectList(new List<SelectListItem>())) %>
This is all very much off the top of my head, so let me know if something needs to be clarified or corrected.
Edit
As noted in my comment, in order to "AJAXify" your page, you don't really want to push everything around in your Model. Instead, it sounds like you want something like this:
Controller action:
public JsonResult GetPagedData(int page, int itemsPerPage, string[] filters)
{
var results = dataRepository.GetPagedItems(pageId, itemsPerPage, filters);
return new JsonResult()
{
Data = results.ToArray();
};
}
JS changes:
var retrieveData = function(path, pageNumber, pageSize, filters, fnHandleCallback) {
// Use the getJSON method to call our JsonResult action
$.getJSON(path, { page: pageNumber, itemsPerPage: pageSize, filters: filters }, function(data) {
fnHandleCallback(data);
});
};
// The path parameter is our JSON controller action
function updateList() {
retrieveData("/Controller/GetPagedData", $("#pageNumber").val(), $("#dropDownId").val(), null, handleResponse);
}
I've intentionally ignored figuring out both the page number and the filters - they would follow essentially the same principles.
Finally, when you're rendering the data you'll put it into your product grid rather than another drop-down.