简体   繁体   English

从Javascript ReturnUrl参数进行的MVC3操作调用始终为null

[英]MVC3 Action Call from Javascript ReturnUrl parameter always null

I am using javascript to load up an Action and finding that when the action method is called one of the parameters "returnUrl" is always null. 我正在使用JavaScript加载动作,并发现在调用该动作方法时,参数“ returnUrl”之一始终为null。 I have confirmed that returnUrl is populated in the javascript correctly using firebug, but somewhere between executing the .load function and the action method the value for returnUrl is lost and set to null. 我已经确认使用Firebug在JavaScript中正确填充了returnUrl,但是在执行.load函数和action方法之间的某个位置,returnUrl的值丢失并设置为null。 I have found that if I remove the "id" parameter and just have the "returnUrl" parameter that returnUrl has the correct value. 我发现,如果删除“ id”参数而仅具有“ returnUrl”参数,则returnUrl具有正确的值。 I have spent many hours trying to figure out what is going on here and am completely stumped, I would apprectiate some help. 我花了很多时间试图弄清楚这里发生了什么,并且完全陷入困境,我会为您提供一些帮助。

My Javascript: 我的Javascript:

<!-- Review Dialog Popup -->
<script type="text/javascript">
function showWriteReviewDialog(gameId, returnUrl) {
    if( $("#Review").length == 0)
    { 
        var url = "@Url.Action("WriteUserReview", "UGDBUser", new { id = "PLACEHOLDER", returnUrl =  Request.Url.ToString() })";

        // ajax load
        $('#writereview').load(url.replace('PLACEHOLDER', gameId));
    } else {
        // clear summary & reviewtext fields
        $('#summary,#reviewtext').val('');

        //reopen the write review dialog which was previously rendered
        $("#Review").dialog({
            modal: true, 
            autoOpen: true,
            resizeable: false
        }); 
    }
};
</script>

My Dumbed Down Action Method: 我的愚蠢动作方法:

     [Authorize]
     public ActionResult WriteUserReview(Guid id, string returnUrl)
     {
        return Redirect(returnUrl);
     }

There must be something wrong with the URL generated. 生成的URL一定有问题。 Also make sure the id is a guid. 另外,请确保ID为Guid。 Here is an example. 这是一个例子。

Option 1 选项1

function showWriteReviewDialog(gameId, returnUrl) {

    var url = '@Url.Action("TestParams", "Home")?id=' + gameId + '&returnUrl=' + returnUrl;
    $("#writereview").load(url);

    //rest of your operations
};

Option 2 选项2

function showWriteReviewDialog(gameId, returnUrl) {

    var url = '@Url.Action("TestParams", "Home", new { id = "guid_replace", returnUrl = "url_replace"})';
    url = url.replace('guid_replace', gameId);
    url = url.replace('url_replace', returnUrl);

    $("#writereview").load(url);

    //rest of your operations
};

Screen shot on hitting the action; 击打动作时的屏幕截图; it returns both the values (have a look at the watch window) 它返回两个值(看一下监视窗口)

在此处输入图片说明

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

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