[英]unable to open view in model popup mvc 3
I want to render a view when user clicks on "Add New" button on the index page.当用户单击索引页面上的“添加新”按钮时,我想呈现一个视图。 I have an Action in the controller which handles Create post.
我在处理创建帖子的 controller 中有一个操作。 Problem here is that i am not able to load the View.
这里的问题是我无法加载视图。 When i click "Add New" button, nothing happens.
当我单击“添加新”按钮时,没有任何反应。 Can someone please point out what am i missing here?
有人可以指出我在这里缺少什么吗?
This is how my Index view looks like:这就是我的索引视图的样子:
<script type="text/javascript">
$(function () {
$('#dialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
title: 'Add New Item',
modal: true,
open: function (event, ui) {
$(this).load('@Url.Action("Country/Create")');
},
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
$('#AddNew').click(function () {
alert('Hello');
$('#dialog').dialog('open');
});
});
</script>
<button id="AddNew" type="button">Add New</button>
<div id="dialog" style="overflow: hidden;">
</div>
Script references:脚本参考:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
Layout.cshtml布局.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</head>
<body>
@RenderBody()
</body>
</html>
--Solution-- - 解决方案 -
I was missing jquery.ui.all.css reference.我缺少 jquery.ui.all.css 参考。
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
I **think** your file order is wrong
jquery-1.5.1.min.js
jquery-ui-1.8.11.min.js
now other files
-------------I think your URL format is also wrong--------- -------------我认为你的 URL 格式也是错误的---------
@Url.Action("Action","Cortoller");
@Url.Action("Create","Country");
$(this).load('@Url.Action("Create","Country")');
try putting your Javascript code between尝试将您的 Javascript 代码放在
$(document).ready(function () {
...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.