views:

749

answers:

1

Is it possible to grab specific elements from a database via the entity framework and display them after clicking a 'Find' button on the page?

Lets say there is a textbox and you have to enter a number. Upon entering a certain number, a certain database table's column will be searched for that number and all instances will be returned (every matching row) but instead of displaying every column in the table, only 3 or 4 columns would be shown. Is that possible? Ive tried a few things with no success.

Also, with my old site, I had a gridview and used a mouseover/click javascript event that would change the color of the whole row upon a mouseover/out and click. Can that be done with a table and/or a gridview in MVC? Thanks in advance.

A: 

that's the great thing about MVC, you can really do anything. For your first question, sounds like a simple Ajax.BeginForm around your textbox.

<div id="mygrid"></div>

<% using (Ajax.BeginForm("/path/to/action/", null, 
          new AjaxOptions { InsertionMode = InsertionMode.Replace, 
          UpdateTargetId = "mygrid" }))  {%>
<%= Html.TextBox("q") %>
<input type="submit" value="search" />
<% } %>

Note the UpdateTargetId that points to the empty div, and the insertionmode that would replace the contents of mygrid with whatever is returned from "/path/to/action/". The action method could simply render a partial view that contains the table columns you want to display :-)

As to your second question, that can be accomplished with a little CSS and maybe jQuery magic :-)

$("#mygrid tr").click(function() {
  $(this).toggleClass("highlighted");
});
Joel Martinez
Thanks for responding, but how do I actually fetch the data necessary to fill the grid?
dangerisgo
well, that depends on what you're using as your data layer. nHibernate, LinqToSql, Entity Framework, simple ADO.NET.
Joel Martinez
I'm using Entity Framework.
dangerisgo
Is there a specific question that you have about querying for data with the Entity Framework?
Joel Martinez