What is view engine? What does it actually do?

后端 未结 10 907
名媛妹妹
名媛妹妹 2020-12-13 08:24

I started learning ASP.NET MVC3.

So, while reading tutorials online and in books, I came across this term \"view engine\" quite frequently. I don\'t know

10条回答
  •  醉话见心
    2020-12-13 09:12

    The view engine is what's responsible for rendering your view, and converting your code into glorious HTML. As such, they are directly responsible for HOW you need to write code in your views.

    There's basically two ones you need to care about: ASPX and Razor. Razor is, in my opinion, much sleeker and easier to use, at the cost of only being supported in MVC3.

    For example, a code block in ASPX might look like this:

    <% foreach(var item in Model) { %>
        
            <%: item.Name %>
        
    <% } %>
    

    Whereas the Razor equivalent will look like this:

    @foreach(var item in Model) {
        
            @item.Name
        
    }
    

提交回复
热议问题