![](/img/trans.png)
[英]Url.Action cant find controller method which returns RedirectToAction
[英]@Url.Action returns a null value within the jQuery .load() method
我是MVC的新手,因此请保持简单而具体的解释。 我本质上是在尝试使用jQuery和@Url打开模式对话框.Action始终返回空值。 当我放弃@ Url.Action并对路径进行硬编码时,它可以正常工作。 这是下面的代码。
脚本:
<script type="text/javascript">
function popupMobileDialog() {
$('#dialog').dialog({
autoOpen: false,
width: 700,
height: 500,
resizable: false,
title: 'CURewards Mobile Apps',
modal: true,
open: function (event, ui) {
$(this).load('@Url.Action("MobilePopup", "MobilePopup", new { area = "Innerge.Plugins.PSCU"})');
//$(this).load('MobilePopup/MobilePopup');
},
buttons: {
"Ok": function () {
$(this).dialog("close");
}
}
}).dialog("open");
}
</script>
控制器:
[Export(typeof(IController))]
[ExportMetadata("Name", "MobilePopup")]
[ExportMetadata("Plugin", true)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class MobilePopupController : Controller
{
public ActionResult MobilePopup()
{
return View();
}
}
视图:
@{
Layout = null;
}
<p style="text-align:center; font-weight:bold;">Yay!!! This is the modal popup window I've been waiting for.</p>
关于我在做什么错的任何想法,请让我知道。 如果您需要更多信息,请告诉我。 谢谢!!!
以下代码行解决了我的问题。
$(this).load('@Url.Action("MobilePopup", "MobilePopup", new { area = ""})');
我的layout.cshtml文件位于/ Views / Shared中,而MobilePopupController位于根结构(/ Controllers)之外的另一个区域中。 因此,通过添加“ new {area =”“}”参数,它告诉ASP.NET,它将在项目的根/默认区域中找到控制器,该区域是任何area文件夹之外的项目结构。 如果没有area参数,它将告诉ASP.NET在控制器的当前区域中查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.