views:

450

answers:

1

Hi everyone!

I'm trying to accomplish this with Linq to Sql and Asp.Net MVC:

I have a Drop Down List with options Country, City and State. And beside it, there is a textbox. So, an user will, for instance, select City and will type "new york city" in the textbox and the application will show himm the results of his choice.

So, how can I make a dynamic query based on what the user selected in the drop down? I'm not trying to make something hardcoded, because I intend to use this query with some other things.

Thanks a lot!!

+1  A: 

It sounds like you are looking for an AJAX enabled auto complete textbox. Something similar to Ben Scheirman's blog article http://flux88.com/blog/jquery-auto-complete-text-box-with-asp-net-mvc/ would do the trick.

Using that article as a base for your code you would change the autocomplete javascript behavior to include the City/State/Country parameter in your call to the MVC controller.

<script type="text/javascript"> 
    $(document).ready(function() { 
    var dropdownValue = $("#DropDownListId").val();
    $("input#city").autocomplete('<%= Url.Action("Find", "City") %>' + dropdownValue + '/'); 
    }); 
</script>

From the Linq 2 SQL side of the application it is hard to give you specific guidance on how to accomplish this because we know nothing about the design of your database. But I would image the query would be fairly simple to write.

Does that answer your question?

Gavin Osborn
hmmm... not exactly. I really need how to know with drop down selected value.. :-(
AndreMiranda
I've updated the question to include one possible way of getting the drop down value and including it in your autocomplete call.
Gavin Osborn
heheh Not again... I really need the LinqToSql part... :-( But, thanks!
AndreMiranda