Click here to Skip to main content
15,944,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have worked on jquery ajax before but got stuck into an issue. Let me share the problem with you all.


Folder Structure
There are 2 projects in a solution - Project 1 and Project 2. In Project 1 there is a jquery ajax call, where the call is made to a .cs file (AlleryControl.cs) in Project 2 and it has a method - generateToolbarMenu().
AllergyControl.cs file is a partial class file and the method access specifier is 'internal'.

While running the application, it is showing "404 Error" and it says the file not found.

This is an MVC project. Only the Project 1 is being hosted. When I am running the application, it is pointing to Project 1. Then if the filepath is going wrong, how to specify the filepath for the .cs file in Project 2?

Or is it something else which I need to check?

What I have tried:

I have tried all of the following one by one:

1. Changed the "type" property in jquery ajax from "POST" to "GET".
2. Added [WebMethod] attribute for the function and also changed the access specifier from "internal" to "public".
3. While running the application, changed the filepath on the fly, but could not identify what should be the actual filepath?
Updated 24-Sep-18 7:55am
F-ES Sitecore 24-Sep-18 4:39am    
You don't "call" cs pages. cs files are just text files that contain code to be compiled into classes, and it is those classes that you are looking to call.

Seeing as what you are trying to do is literally impossible you'll need to at least post some of the code. If you are looking to call c# code via ajax then you need your MVC project to host a web api, or the ajax can call an action on a controller directly. google "c# ajax call controller action" for examples on how to do that.
Member 11072126 24-Sep-18 6:09am    
Yes. I also know the same. We cannot call any method from a .cs file. I know how to call any action method in the controller. Thank you very much.
ZurdoDev 24-Sep-18 7:50am    
To call a function in a different project you add a reference to that project.
Member 11072126 24-Sep-18 8:25am    
Yes. Correct.
Anyways, thank you all for your responses. Its been done. I created an action method inside a Controller and pointing ajax call to that.
ZurdoDev 24-Sep-18 8:27am    
OK, please post something as a solution so that this no longer shows in the Unanswered list.

1 solution

Why don't you try creating an action method inside a controller. Then point the ajax call to that.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900