This is mostly brainstorming; I’ve written some proof-of-concept (POC) code, and would love feedback. I expect to hear that this has already been done earlier/better/prettier.
A very common pattern for our intranet sites is a page with search controls, a submit button, and an output section listing the results. I want to give this pattern a few features that suit my team:
MVC Controller methods:
1: public ActionResult Index()
2: {
3: // Very simple view with just search controls; no logic/data.
4: return View();
5: }
6:
7: public ActionResult IndexResults(string state = null, string revision = null,
8: string assignedTo = null, string keywords = null, string labs = null,
9: int[] multiselect = null)
10: {
11: // Load data, return partial view with results.
12: }
One thing to note is that the controls returned by the Index view bear the same names as the arguments for the IndexResults view. You’ll see why in a minute…
Javascript code for the page:
1: $(function () {
2:
3: $("#btnSearch").click(function () { runSearch() });
4: DD.queryHashToForm();
5: runSearch();
6: });
7:
8: function runSearch() {
9:
10: var urlObj = DD.formToQueryHash();
11: DD.ajaxPost(
12: "/Issues/IndexResults",
13: urlObj,
14: function (res) {
15: $("#divResults").html(res);
16: }
17: );
18: }
That’s it; together, these ingredients result in a page with a persistent URL that loads the data using AJAX, and even displays a progress indicator during the load. As you can see, this is code that’s very easy to write if you were making such a page.
So – here are the interesting lines from the JS above (note that “DD” is the library containing all the POC code):
Is this interesting? Should I post some of the code?