Hi!
I ahve been woring in ASP. NET for many years and is now starting my first MVC 3.0 project. Things are rather confusing, but I do like the pattern itself.
How I have a small question, for someone who is good at explaining things..
In my view I have this code (a search page and a list)
And my controller looks like this:Code:@using (Html.BeginForm()) { <p> Find by name: @Html.TextBox("SearchString") <input type="submit" value="Search" /> </p> }
How on earth is the search string parsed from the view to the controller? How is the textbox name searchString connected to the parameter of the Index method? Is it just the name? I have read it is a HTTP form post, but is all that stuff abstracted away from the developer?Code:public ViewResult Index(string sortOrder, string searchString) { ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "Date desc" : "Date"; var students = from s in db.Students select s; if (!String.IsNullOrEmpty(searchString)) { students = students.Where(s => s.LastName.ToUpper().Contains(searchString.ToUpper()) || s.FirstMidName.ToUpper().Contains(searchString.ToUpper())); } switch (sortOrder) { case "Name desc": students = students.OrderByDescending(s => s.LastName); break; case "Date": students = students.OrderBy(s => s.EnrollmentDate); break; case "Date desc": students = students.OrderByDescending(s => s.EnrollmentDate); break; default: students = students.OrderBy(s => s.LastName); break; } return View(students.ToList()); }
It feels very abstract at the moment. Note that I have tread two books on C# 4.0 and MVC 3 so I might be suffering from information overload...![]()
If someone can provide a nice clear explanation about this I would be more than grateful! I am supposed to explain this later to a junior developer (lol).
/Henrik




Reply With Quote