You cannot actually call the scripts section in your partial view and execute this method there. That is by design. See Darin's post here
What you can do is, keep this method in the main view. You can still conditionally execute this from your partial view if needed.
So in your main view
<script>
var mySettings = mySettings || {};
mySettings.shouldIShowSpectrum = false;
</script>
@Html.Partial("YourPartialViewNameHere")
@section scripts
{
<script>
function enableSpectrum() {
$(".basic").spectrum({
color: "#f00",
change: function (color) {
$("#basic-log").text("change called: " + color.toHexString());
}
});
}
// You can put the above method in an external js file as well.
$(function() {
if (mySettings.shouldIShowSpectrum)
{
enableSpectrum();
}
});
</script>
}
and in your partial view, you can set the mySettings.shouldIShowSpectrum
value true so that when the page gets rendered it will enable your plugin.
<h5>My Partial</h5>
<input type='text' class="basic" />
<em id='basic-log'></em>
<script>
console.log("going to enable the plugin");
var mySettings = mySettings || {};
mySettings.shouldIShowSpectrum = true;
</script>