Note that there are some explanatory texts on larger screens.

plurals
  1. POMy action controller code looks amateurish
    text
    copied!<p>First post time,</p> <p>I've been playing around with MVC abit... I have a view which has multiple input fields, some of these fields can be blank on post.</p> <p>The action method inside the controller for the post looks something like this</p> <pre><code>public ActionResult Filter(int? id, string firstName, string lastName, bool? isMember) </code></pre> <p>I've been using the DynamicQuery extension which has been kicking around in order to perform dynamic Linq querys on my database and I've encapsulated this in a Search object which is passed to the data access layer for execusion.</p> <p>However, I also have a customized ViewData object which is passed back to the view for displaying the input values and the results of the query.</p> <p>It all looks a little nasty in code as I'm having to set both the Search object properties AND the ViewDatas.</p> <pre><code>public ActionResult Filter(int? id, string firstName, string lastName, bool? isMember) { var search = new Search { Id = id, FirstName = firstName, LastName = lastName, Member = isMember }; var memberViewData = new MemberViewData { Id = id, FirstName = firstName, LastName = lastName, Member = isMember }; memberViewData.Results = _dataRepository.GetMember(search); return View("Search", memberViewData); } </code></pre> <p>Am I over thinking this and really should just pass the values to the data access layer and populate the ViewData in the controller, or is there a much more elegant pattern or practise I could use?</p> <p>Sorry if this seems dump, not allot of people to bounce ideas off and time to dig into the framework.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload