我有一個CSHTML頁面,讓這些錯誤:
Uncaught ReferenceError: $ is not defined TabNotes:2
(anonymous function) TabNotes:2
TabNotes:12Uncaught ReferenceError: ko is not defined TabNotes:12
(anonymous function) TabNotes:12
(anonymous function) TabNotes:23
什麼會導致這樣的錯誤?我找不到任何理由。我試着包裝的JavaScript函數$(文件)。就緒(函數(){但沒有任何工作的代碼如下
@model test.Web.Framework.Areas.Administration.Models.TabNotesModel
@using (UI.DocumentReadyScript())
{
if (Model.meta.id.HasValue)
{
UI.jQuery("#tbl" + Model.meta.modelname).flexigrid(Model.Grid);
}
}
<form method="post" action="@Url.Action("TabNotes", new { cmd = "refresh" })" id="@Model.meta.modelname">
<div class="ui-state-highlight ui-corner-all highlight" data-bind="visible: meta.message">
<span class="ui-icon ui-icon-info"></span><strong data-bind="text: meta.message">
</strong>
</div>
@using (UI.BeginBlock("Administation.TabNotes", UI.Label("Notes", "Notes").ToString(), test.Web.Framework.Core.enumIcons.pencil, false, false))
{
<table id="@("tbl" + Model.meta.modelname)">
</table>
}
</form>
<script type="text/javascript">
(function() {
var viewModel=ko.mapping.fromJS(@Html.Raw(UI.JavascriptEncode(Model)));
viewModel.getData=function() { return ko.mapping.toJSON(this ); };
viewModel.setData=function(data){
$('#tbl'+this.meta.modelname()).flexigrid(data.Grid);
ko.mapping.updateFromJS(this,data);
};
$('#@Model.meta.modelname').koform({viewmodel: viewModel , validate : {errorElement:'p' } });
$('#@Model.meta.modelname').koform('applyBindings');
$('#load-partial').click(function() {
$('#partial').load('@Html.Raw(@Url.Action("CreateNote", "Entity", new {modelEntity = @Model.meta.entity, itemId = @Model.meta.id}))');
});
})();
</script>
<div id="partial"></div>
<button type="button" id="load-partial">Create Note</button>
編輯:。 jQuery的會從母版頁加載
您是否記得包含jQuery? – Grexis 2012-01-03 23:55:18