Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 27852

Moving functions from Default.cshtml to App_Code\Functions.cshtml

$
0
0
Hello,
this code is working fine
@{
    var db = Database.Open("bakery");
    var products = db.Query("SELECT * FROM PRODUCTS").ToList();
}

@foreach (var p in products) {
        @p.Name<br>
}

I just would like anyway to move the creation of products together with the db opening into an helper file or function file.

From my Default.cshtml I just want to cycle on my variables, while I would like to keep the creation of the lists in a separate file (App_Code folder) which has all the functions and where the database connection is handled.

How do I do it? Suggestions?
Thank you

Viewing all articles
Browse latest Browse all 27852

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>