我想使用@Ajax.ActionLink 来弹出一个表单,所以我在我的 cshtml 页面中做了这个:
@Ajax.ActionLink("click ", "AddToMembers", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup" })
<div id="result" style="display:none;"></div>
并添加此脚本:
<script type="text/javascript">
$(document).ready(function () {
$("#result").dialog({
autoOpen: false,
title: 'Title',
width: 500,
height: 'auto',
modal: true
});
});
function openPopup() {
$("#result").dialog("open");
}
</script>
在我的 Controller 中添加了这个功能:
[HttpGet]
public PartialViewResult AddToMembers()
{
return PartialView();
}
但是当我点击表单中的“点击”时,新页面会在浏览器中打开。不在我的弹出表单中
有什么问题 ???
最佳答案
我怀疑您忘记在页面中包含以下脚本:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
该脚本用于对
Ajax.ActionLink
生成的 anchor 进行 AJAX 化 helper 。另外,您正在使用 jQuery 对话框,请确保您已引用 jQuery UI:<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>
关于asp.net-mvc - 使用@Ajax.ActionLink 弹出一个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9311502/