4

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

    });
3
  • How does your controller look like - I mean the parameters?
    – codingbiz
    Commented Apr 28, 2013 at 19:14
  • How are you using your Url.Action? Is this being used with to set the href of and anchor tag? Commented Apr 28, 2013 at 19:35
  • look at edit now. Regards
    – whoah
    Commented Apr 28, 2013 at 19:38

1 Answer 1

22

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.