JQuery won't pass anything to ASP.NET Controller JQuery won't pass anything to ASP.NET Controller json json

JQuery won't pass anything to ASP.NET Controller


It appears you are including Razor code: @Url.Action("User", "CheckInMood") in your JavaScript file.

Since this is a javascript file, Razor will not be used to render that value so it will treat it as a literal.

What you'll want to do is pass in the URL from your View into JavaScript.


change:

data: JSON.stringify({ mood: $("#DisplayMood").val() })

to:

data: { mood: JSON.stringify($("#DisplayMood").val()) }

You need to stringify the parameter's value, not the parameter name.


@Url.Action is only usable from within the razor file itself then, being it in the script tag and so, and now where else? (Just to clarify)