Skip to content
Advertisement

Ajax call Into MVC Controller- URL Issue

I’ve looked at the previously-posted jQuery/MVC questions and haven’t found a workable answer.

I have the following JavaScript code:

JavaScript

When calling the Url the post looks like:

JavaScript

Why does it return it like this (the logic behind it) and what’s a solution?

P.S.: Additional Information: %22 is the URL Encoding Reference for <<“>> character

Advertisement

Answer

In order for this to work that JavaScript must be placed within a Razor view so that the line

JavaScript

is parsed by Razor and the real value replaced.

If you don’t want to move your JavaScript into your View you could look at creating a settings object in the view and then referencing that from your JavaScript file.

e.g.

JavaScript

and in your .js file:

JavaScript

or alternatively look at levering the framework’s built in Ajax methods within the HtmlHelpers which allow you to achieve the same without “polluting” your Views with JS code.

Advertisement