Accessing the Rasor variables inside a foreach

1

I'm trying to list the contents of a table, showing in each item the items of another table that maintains a relation with the first (1: N). For this I need 2 select, being the 2nd select based on each line of the result of the 1st select. The problem is that I do not know how to identify, inside the SELECT string, the value brought by the RASOR relative to the id field.

@{
    string query = "SELECT id, tituloTopico FROM Topicos";

    var resultados = base_dados.Query(query);
    foreach (var linha in resultados)
    {       
        @linha.tituloTopico        
        string query1 = "SELECT tituloCatalogo FROM Catalogos WHERE Catalogos.id_Topico = @linha.id";
        var resultados1 = base_dados.Query(query1);
        foreach (var linha1 in resultados1)
        {
            @linha1.tituloCatalogo
        }
     }
 }

@ line.id is not recognized within the Select statement. I'm using cshtml and rasor page.

    
asked by anonymous 06.09.2017 / 12:12

1 answer

1

This type of logic must be run on the Controller layer (assuming you are using MVC).

Second this , Razor aims to:

  

Razor comes in ASP.NET MVC 3, bringing the new concept of View Engine, which is nothing more than a template that implements a different syntax for building Web pages in ASP.NET, making the web encoding pages much simpler and more dynamic. Razor is an additional option for building Web pages, further simplifying interface layer encoding. It is especially useful in ASP.NET MVC3 applications, where you look for a clean and uniform code throughout the application.

Queries in database and other logics should be implemented in the Controller.

    
06.09.2017 / 19:30