简体   繁体   English

@ Url.Action在jQuery .load()方法中返回空值

[英]@Url.Action returns a null value within the jQuery .load() method

I'm very new to MVC so please keep the explanations simple and specific. 我是MVC的新手,因此请保持简单而具体的解释。 I essentially am trying to open a modal dialog using jQuery and @Url.Action keeps returning a null value. 我本质上是在尝试使用jQuery和@Url打开模式对话框.Action始终返回空值。 When I forego @Url.Action and hardcode the path, it works fine. 当我放弃@ Url.Action并对路径进行硬编码时,它可以正常工作。 Here's the code below. 这是下面的代码。

Script: 脚本:

<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>

Controller: 控制器:

[Export(typeof(IController))]
[ExportMetadata("Name", "MobilePopup")]
[ExportMetadata("Plugin", true)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class MobilePopupController : Controller
{
    public ActionResult MobilePopup()
    {
        return View();
    }

}

View: 视图:

@{
    Layout = null;
}

<p style="text-align:center; font-weight:bold;">Yay!!!  This is the modal popup window I've been waiting for.</p>

Any ideas as to what I'm doing wrong, please let me know. 关于我在做什么错的任何想法,请让我知道。 If you need any more information, please let me know. 如果您需要更多信息,请告诉我。 Thanks!!! 谢谢!!!

The following line of code resolved my issue. 以下代码行解决了我的问题。

$(this).load('@Url.Action("MobilePopup", "MobilePopup", new { area = ""})');

My layout.cshtml file is located in /Views/Shared while MobilePopupController is located off of the root structure (/Controllers), in another area. 我的layout.cshtml文件位于/ Views / Shared中,而MobilePopupController位于根结构(/ Controllers)之外的另一个区域中。 So, by adding the "new { area = ""}" parameter, it tells ASP.NET that it'll find the controller in the root/default area of the project, which is the project structure outside of any areas folder. 因此,通过添加“ new {area =”“}”参数,它告诉ASP.NET,它将在项目的根/默认区域中找到控制器,该区域是任何area文件夹之外的项目结构。 Without the area parameter, it tells ASP.NET to look in the current area for the controller. 如果没有area参数,它将告诉ASP.NET在控制器的当前区域中查找。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM