简体   繁体   中英

mvc - url.action - second argument is null

Strange problem with my code - please, look at it:

@Url.Action("IdeaVote","Ideas", new { IdeaID = "1", vote = "For" })

values in method (get from debugger):

IdeaID=1, vote=null

And now some magic tips (reverse vote and IdeaID).

@Url.Action("IdeaVote","Ideas", new { vote = "For", IdeaID = "1" })

Again values in method (get from debugger):

vote=for, IdeaID=null

Method IdeaVote (parameters)

    public int IdeaVote(string vote, string IdeaID)

My question is - Why second argument is always null? Why this situation happend?

Regards

EDIT:

My jQuery method with url.action

    $.get("@Url.Action("IdeaVote","Ideas", new { IdeaID = "1", vote = "For" })",function(data)
    {
        if (data == 1) {
            $("#imageVoteAgainst").css("border-width", 0);
            $("#imageVoteFor").css("border-width", 1);
        }

    });

You didn't post the URL generated by your code, but in generl Url.Action creates HTML-encoded links, so I think the problem in your case is that & sign is replaced with & . Try using Html.Raw helper to decode this:

"@Html.Raw(Url.Action("IdeaVote","Ideas", new { IdeaID = "1", vote = "For" }))"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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