0

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?

Let's 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? I've 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?

1 Answer 1

1

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");
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for responding, but how do I actually fetch the data necessary to fill the grid?
well, that depends on what you're using as your data layer. nHibernate, LinqToSql, Entity Framework, simple ADO.NET.
Is there a specific question that you have about querying for data with the Entity Framework?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.