Home Adding a dropdown list outside or RenderBody call
Reply: 0

Adding a dropdown list outside or RenderBody call

user839
1#
user839 Published in July 16, 2018, 6:23 am

I have a .NET MVC project with Razor views and I would like to implement search functionality that consists of a dropdown list, a text box and a search button.

The problem is that I would like to implement this search snippet in my _Layout.cshtml file outside of the @RenderBody() call. This means that the search functionality would be accessible on every page (it would be located at the very top right corner).

I'm trying to find out what is a good way of implementing this. I can get it to work but it would involve adding same code (do get dropdown values) to all controllers and actions.

ViewBag.States = new SelectList(db.States, "Id", "Name");

Is there a better way to implement this? It feels very repetitive to do it this way.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313681 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO