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 8139959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:00:09+00:00 2026-06-06T12:00:09+00:00

Question: What is a clear, safe and systematic way to call my MVC controllers/actions

  • 0

Question:

What is a clear, safe and systematic way to call my MVC controllers/actions from JavaScript, but keep the related URLs in a central place for updating when controllers change? Or to dynamically generate the URLs at run-time? Or to get compile-time checking for AJAX controller linkage?

Research/Past Attempts:

I’ve recently plugged in T4MVC to my MVC project. Great! Compile-time checking for controller linkage in my views – but I still have controller URLs littered all over my JavaScript. Worse, I have evolved how I do it over the project lifetime, so I do it multiple ways that I’m still not satisfied with.


1) One way:

locationAutoComplete = new AjaxQueue({
 Controller: "Utilities", // null for current controller
 Action: "GetMatchingLocations",
 DataModel: null, // null for raw JSON, or a local model to populate
 MaxQueuedRequests: 0
});

2) Another way:

locationAutoComplete = function (location) {
 return $.ajaxPost(resolveUrl("~/Utilities/GetMatchingLocations"));
}

3) Both 1 and 2 above make use of a project root defined in a Master/Layout JavaScript snippet, but still use unchecked URL strings. So now I’ve started benefiting from T4MVC by simply defining controller strings in my .CSHTML view:

var locationLookupController = @Url.Action(MVC.Utilities.GetMatchingLocations());

4) The SO article ( Ajax call Into MVC Controller- Url Issue ) addresses this a little. It talks about method 3, but also suggests using the AjaxHelper namespace. Since I make heavy use of jQuery AJAX with some pretty customized interactions (e.g. loading results into a local data model, not at a click event but at a timed interval), I don’t think it will help me much. Today I don’t even include the MS AJAX JavaScript code on any of my pages.

Thanks!

  • 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-06T12:00:13+00:00Added an answer on June 6, 2026 at 12:00 pm

    Continue to use T4MVC. Mix it in with a little jQuery and HTML5 data-* attributes. Here’s an example:

    <div data-location-lookup-url="@Url.Action(MVC.Utilities.GetMatchingLocations())">
    
    ...
    
    locationAutoComplete = function (location) {
        var url = $('[data-location-lookup-url]').data('location-lookup-url');
        return $.ajaxPost(url);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As it is clear from question, if I convert a normal method to static
I am not sure how clear my question is by the title, but I
I don't know if my question will be clear or not, but i'm starting
Question is pretty clear I guess. I have a UISegmentedControl as my tableViewHeader. I
My question is not clear at title [i can not write it exactly] e.g
Sorry if question is not clear. My vocabulary for terminology is bad. Anyways I
I think the question title is clear enough: is is possible to stable_sort() a
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
The question might not be clear, so i will explain further. I saw some
My question is how can i clear the editText field after i have saved

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.