參照Link,我從MVC創建了一個UI對話框。
這裏是我的代碼:
在Layout.cshtml對象不支持屬性或方法對話框
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="../../Content/smoothness/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.10.2.custom.min.js" type="text/javascript"></script>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
Index.cshtml
<h2>jQuery UI Hello World</h2>
<button id="show-dialog">Click to see jQuery UI in Action</button>
<div id="dialog" title="jQuery UI in ASP.NET MVC" >
<p>You now have the power of ASP.NET, the simplicity of client-side scripting with jQuery, and the looks of jQuery UI. Congrats, web slinger!</p>
</div>
<script language="javascript" type="text/javascript">
$(function() {
$('#dialog').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() { $(this).dialog("close"); },
"Cancel": function() { $(this).dialog("close"); }
}
});
$("#show-dialog").button().click(function() {
$('#dialog').dialog('open');
return false;
});
});
</script>
我都在IE和Firefox檢查。 Firefox拋出「Typeerror $(...)。對話框不是函數」和IE拋出對象不支持屬性或方法'對話框'。
有任何建議。我的代碼中有什麼錯誤。爲什麼出現對話錯誤?
爲什麼你的'Index.cshtml'使用WebForms語法?你所顯示的是一個無效的剃刀視圖。 – 2013-03-28 10:47:01
是的。你是對的。請檢查我的編輯。 – kk1076 2013-03-28 10:52:15