Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Razor pages and expressions, correct way to use the syntax

$
0
0

Hello,

i'm a total noob with .NET Core and i'm currently working on a website entirely built with .NET CORE 2 and Razor pages. I've been following some tutorials and I love the framework, especially Razor Pages (.Net Core 1 seemed too bloated with directories and stuff).

I'm kinda confused by some aspects of Razor Pages, for example, what's the best way to use variables and dynamic data with Razor? If i have a "Product" model with some data in it there are multiple way to accomplish the same task:

<!-- 1st method -->
<p>@Product.Description</p>

<!-- 2nd method -->
<p>@Html.DisplayFor(modelItem => item.Product.Description)</p>

<!-- 3rd method -->
<p>@Html.DisplayNameFor(model => model.Product.Description)</p>

What's the difference and why does it matters? If you can suggest a good tutorial to learn this kind of stuff i would greatly appreciate! Thank you.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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