Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:07:33+00:00 2026-06-12T12:07:33+00:00

i have written a jquery functions in external JS file and included that file

  • 0

i have written a jquery functions in external JS file and included that file where ever i required.

In jquery function i called action method from my controller. Now my problem is i’m not able to locate that action method path from the external JS. It is throwing error that is method not found like that.

Now how i can write the action path name in the external JS which will work from any where.

I tried following for mentioning/calling action method –

1. url: "/Employee/AutocompleteSuggestions" 


2. url: "AutocompleteSuggestions"

3. @Html.Raw(Url.Action("AutocompleteSuggestions", "Employee", new { @term = "Term", @moduleName="ModuleName"}))

3rd is not working because of razor syntax.

How to resolve this problem ?

I used the JS like below –

       $.ajax({
                url: "AutocompleteSuggestions",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                type: "POST",
                data:
                    JSON.stringify({
                        term: request.term,
                        moduleName: "Employee"
                    }),
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item.FullName, value: item.Id }
                    }
                    ))
                },
                error: function (xhr, ajaxOptions, thrownError) { alert(thrownError); }
            })
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:07:35+00:00Added an answer on June 12, 2026 at 12:07 pm

    One issue you have here is that you will probably need to use a global; which could be vulnerable to script attacks. See my original answer for the most naive implementation.

    I think this is probably pretty safe – but there are much better Javascript gurus out there who might have a better answer.

    In your layout/master you can just output a script block like this (I’m using Razor):

    <script>
      function myActionMethods(){
        this.MyActionMethod = function(){
          return '@Url.Action("Action", "Controller")';
        };
      }
    </script>
    

    And then include your script after that, using something like this:

    var methods = new myActionMethods();
    $.get(methods.MyActionMethod());
    

    When you need to use that URI in your script (just demonstrating here with a jQuery Get).

    In response to your comment on @David’s answer

    Sure; you can use Razor to output the JS: Just write a controller action that fires a Razor view which returns javascript (although you’ll have to do a little mucking around with the response types) but if you do this you lose all caching/compression benefits on that script and then you have to write that all back in again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a jquery ajax function that I have added to js file
I have written a simple jQuery.ajax function which loads a user control from the
I have written a script that fires a jQuery POST to retrieve data from
I have written one custom paremeterized jquery function for fadein and fade out. That
I have 2 jQuery functions that basicly are written the same except for their
This is written in an external .js with jquery... I have two windows that
I have written a form using the jQuery .post() function to post the data
Hi I am learning JQuery and I have written a small function where I
I have written a cascading drop down list using JQuery. The code that I
I am trying to fetch wcf service from jquery. I have written below code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.