1

I need your help, I have written this code to render the "~/bundles/jqueryval"

The view Code

@model workflow.DataHolders.NewCompany

<link href="@Url.Content("~/sharedfiles/css/forms/addnew.css")" rel="stylesheet" type="text/css" />
<div id="Add_container">

    @if (!ViewData.ModelState.IsValid)
    {
        <div id="validationMessage">Please Correct The Errors Below</div>
    }

    @using (Html.BeginForm("ValidateAndSignUp", "Accounts", FormMethod.Post))
    {
        @Html.AntiForgeryToken()

        @Html.ValidationMessage("CompanyName");
        <span class="field_title">Company Name: </span>
        @Html.TextBox("CompanyName")

        @Html.ValidationMessage("Email");
        <span class="field_title">Email: </span>
        @Html.TextBox("Email")



        @Html.ValidationMessage("Country");
        <span class="field_title">Country Name: </span>
        @Html.TextBox("Country")

        <span class="field_title">About The Company: </span>
        @Html.TextArea("Description")



        <input type="submit" value="Create New Account">


    }
</div>
<div class="get_connected_message">
    <h1>Get Connected with your Customers</h1>
</div>

<div class="get_connected_message">
    <h1>Build your profissional buisness world</h1>
</div>

<div class="clear"></div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Master Page Code

<!DOCTYPE html>
<html>
<head>
    <title>MACE CRM</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/workflow/sharedfiles/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/workflow/sharedfiles/css/main.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>



<body>

    @Html.Partial("~/Views/shared/header.cshtml")

    <center id="body_container">
        <div id="content">
           @RenderBody()
        </div>
    </center>
    @Html.Partial("~/Views/shared/footer.cshtml")
</body>
</html>
<link rel="stylesheet" href="/workflow/sharedfiles/css/smartDevicesVersion.css">

but unfortunately I get this error

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/MasterPage.cshtml": "Scripts".

so please could anyone help me to resolve this problem.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Mo Haidar
  • 3,748
  • 6
  • 37
  • 76

1 Answers1

1

You need to declare the section within your "master page":

@RenderSection("Scripts", false)

Probably the best idea to include this in the head tag.

Otherwise it doesn't know what to do with your Scripts section defined in your child view.

The second parameter, which I've set to false is whether or not the section is required. If you set this to true and one of your child pages doesn't contain the section, you'll get a server error complaining that the section is missing.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
  • what is second parameter? – Ehsan Sajjad Jun 18 '15 at 10:08
  • 1
    @EhsanSajjad I've added an explanation to my answer :) – Mathew Thompson Jun 18 '15 at 10:09
  • @mattytommo Thanks a lot that was helpful. – Mo Haidar Jun 18 '15 at 10:13
  • @Mohammad No problems glad I could help :) – Mathew Thompson Jun 18 '15 at 10:17
  • @mattytommo Why include it in the head tag? it will only slow down the page. Best to include it in the footer, one of the last elements to load. This will allow the HTML to be rendered first. You don't need the validation js untill you start typing. If you do not have html, there is nothing to type in.. – Mihai Tibrea Jun 22 '15 at 15:11
  • @MihaiTibrea This is a common argument with JS -> head vs footer. I personally prefer it being in the head tag, see this question here: http://stackoverflow.com/questions/2837921/is-it-bad-practice-to-embed-javascript-into-the-body-of-html – Mathew Thompson Jun 22 '15 at 15:15
  • i understand that it is your personal preference, but you should explain to the user that accepted the anwer why you prefer a certain location if you make such a suggestion :) – Mihai Tibrea Jun 22 '15 at 15:20
  • this has a very good explanation on this subject: http://stackoverflow.com/questions/436411/where-is-the-best-place-to-put-script-tags-in-html-markup so if you place them in the header, like @mattytommo suggested, make sure to add the correspoding **async** or **defer** tags – Mihai Tibrea Jun 22 '15 at 15:25