6

My mvc view layout is null. how can i add script inside view.

@{
   Layout = null;
}

@section Scripts{
<script type="text/javascript">

    $(document).ready(function () {
        $('#txtChild1').on('change', function () {
             $("#C1Age1").show();
        });
    });

</script>
}

Error show

cannot resolve section 'Scripts'

3 Answers 3

7

If you use Layout = null then you don't need to use @section Scripts any more. you can simply use script tag.

Example:

@{
   Layout = null;
}

<script type="text/javascript">
    $(document).ready(function () {
        $('#txtChild1').on('change', function () {
             $("#C1Age1").show();
        });
    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

4

If you are not using layout page then you need not to add section. add scripts as you add them on a html page.

@{
   Layout = null;
 }
 <script type="text/javascript">

    $(document).ready(function () {
        $('#txtChild1').on('change', function () {
             $("#C1Age1").show();
        });
    });

</script>

Comments

3

You can also add script block without section if it is not mandatory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.