whoah
whoah

Reputation: 4443

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);
        }

    });

Upvotes: 4

Views: 4837

Answers (1)

Konrad Gadzina
Konrad Gadzina

Reputation: 3404

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" }))"

Upvotes: 22

Related Questions