簡體   English   中英

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

[英]@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM