Write css for a separate page in mvc3 project

I am a thing, I misunderstood something, sorry for that if you are embarrassed.

I want to place Javascript or Css in the Head of my page [which is displayed in the browser]. when I try to fit them, I find that it is inside the body not inside the head tag.

i know that i can easily put in head if i not inherit them from master page.

but how can I put on my page if I inherit them from the main page.

I want to enable the MVC 3 project, and my page is written using Renzor viewenzine.

+3
source share
2 answers

In the header section of the layout page add

RenderSection("head")

call. Then in Razor mode add

@section head {
 @myincludemarkup
}

Where "myincludemarkup", of course, is the html markup of your script / stylesheet links.

edit:

( ) :

<head>
@RenderSection("head")
</head>

"", , @section ..

, ,

<head>
@RenderSection("head", optional:true)
</head>

:

http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx

: :

@inherits System.Web.Mvc.WebViewPage<dynamic>

@using Razor
@using Razor.Models


@{
    View.Title = "Index";
    LayoutPage = "~/Views/Shared/_Layout.cshtml";
}

<h2>@View.Message</h2>

@{
    UserManager.product prod =  UserManager.getUserinfo();
 }
@prod.Price
@prod.Title
@prod.ID
<h2></h2>

@section head {
 @myincludemarkup
}
+8

. .

+1

Source: https://habr.com/ru/post/1757455/


All Articles