Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:00:18+00:00 2026-06-05T02:00:18+00:00

This is my _Layout.cshtml <html> <head> @RenderSection(Script, false) </head> … </html> This is a

  • 0

This is my _Layout.cshtml

<html>
    <head>
        @RenderSection("Script", false)
    </head>
    ...
</html>

This is a simple edit page edit.cshtml

@model Shop.Models.Product
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.EditorForModel()

and this is ~/Views/Shared/EditorTemplates/Product.cshtml

@model Shop.Models.Product
@section Script {
    <script>alert("hello");</script>
}
...

@section Script{...} does not work in Product.cshtml because of EditorForModel. How can do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:00:19+00:00Added an answer on June 5, 2026 at 2:00 am

    Sections work only in views, not in partials. An editor template is a special kind of partial. It’s bad practice to put javascript in partials anyway, so I would simply declare the section in the Edit.cshtml view.

    But if you very much insist on putting your scripts in the middle of your markup, since Razor doesn’t support sections in partials, you could implement custom helpers to achieve that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a top-level _Layout.cshtml that looks something like this: <html> <head> @RenderSection(Header, required:
I have this menu in _Layout.cshtml : <td class=MenuStructure> <ul id=menu> <li>@Html.ActionLink(First Page, Page1Action,
I have something like @{ Html.RenderPartial(@~/Views/Management/_Main.cshtml); } Can I change this view without page
I have an Index.cshtml view: @model AttendenceModel @{ Layout = ~/Views/Shared/_Layout.cshtml; } @using (Html.BeginForm(VisOppsummering,
I use @RenderSection(Contextual, false) within my _Layout.cshtml to allow different views to render their
In _Layout.cshtml I have the following defined in the tag: @RenderSection(JavaScript, required: false); The
I have a layout page thusly <!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <script src=@Url.Content(~/Scripts/jquery-1.7.1.min.js) type=text/javascript></script>
When I created my first empty MVC 3 project, this is the /Views/Shared/_Layout.cshtml file's
When i try to do this: public ActionResult Index(string page) { IndexViewModel model =
Problem: Given this nested layout structure: ~/Views/Shared/_layoutBase.cshtml ~/Views/Shared/_layout.cshtml Where _layoutBase.cshtml is the layout for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.