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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:30:32+00:00 2026-06-08T05:30:32+00:00

I have an MVC app which has a home controller with the method GetResult

  • 0

I have an MVC app which has a home controller with the method GetResult in it:

public int GetResult()
        {
            return 3;
        }

I call it in a javascript file using:

$.post('/Home/GetResult', null, function (data) {

        alert(data);

    });

and it works fine.

However I tried to use a none hardcorded way of calling it

$.get('@Url.Action("GetResult", "Home")', null, function (data) {

        alert(data);

    });

It’s not working I’m getting a 500 errir.

It’s trying to get to the URL:

http://localhost:xx/Home/@Url.Action(%22GetResult%22,%20%%22Home%22)

Well this is obviously isn’t right.

Anyone know what I’m doing wrong?

  • 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-08T05:30:34+00:00Added an answer on June 8, 2026 at 5:30 am

    You cannot use Razor syntax inside a JavaScript file. Razor is a server-side scripting construct that needs to be parsed by ASP.Net to function.

    You have two options:

    Option One:

    Move the script into the .cshtml view file.

    Option Two:

    Create a JavaScript function that accepts the url as a param and call it from the view:

    function foo(posturl){
        $.post(url, null, function (data) {
            alert(data);
        });
    }
    
    /* View */
    foo('@Url.Action("GetResult", "Home")');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC app which has its routes defined with the final route
I have an MVC app in Extjs 4 which has a View (extending Ext.panel.Panel
I have an ASP.MVC application which has a silverlight app inside. I want to
I have successfully created a asp mvc app which basically has interface, service and
I have a Spring MVC application which has a public front-end WAR, an admin
I have an ASP.NET MVC app which has a bootstrapper class that configures log4net
I have an asp.net mvc app which has membership implemented. So a user has
I have an ASP.NET MVC web app which has a really basic subscription system
I have an MVC 3 web app that has an Action which I need
I have an MVC app which has a Tab Panel rendered as the only

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.