Which is considered Best Practice for declaring @section

Coreysan 1,631 Reputation points
2022-11-01T23:29:04.217+00:00

Which is considered best practice in the cshtml file:

  @section css  
  {  
      <link rel="stylesheet" href="~/css/DragDrop.css" />  
  }  

or

  @section css  
  {  
      <link rel="stylesheet" href="@Url.Content("~/css/DragDrop.css")" />  
  }  
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,274 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,716 Reputation points Microsoft Vendor
    2022-11-02T02:35:29.297+00:00

    Hi @Coreysan ,
    You can choose the second one. @Url.Content resolves virtual paths to absolute paths.
    https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.urlhelper.content?redirectedfrom=MSDN&view=aspnet-mvc-5.2

     @section css  
       {  
           <link rel="stylesheet" href="@Url.Content("~/css/DragDrop.css")" />  
       }  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Coreysan 1,631 Reputation points
    2022-11-02T17:31:17.837+00:00

    Thank you so much, as always!

    0 comments No comments