如何在.NET中的同一解决方案中调用来自不同项目的.cs文件中的函数 [英] How to call a function in .cs file from different project in same solution in .NET

查看:63
本文介绍了如何在.NET中的同一解决方案中调用来自不同项目的.cs文件中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



之前我曾在jquery ajax工作但遇到了问题。让我与大家分享这个问题。



问题



文件夹结构

解决方案中有2个项目 - 项目1和项目2.在项目1中有一个jquery ajax调用,其中调用是在项目2中的.cs文件(AlleryControl.cs),它有一个方法 - generateToolbarMenu()。

AllergyControl.cs文件是一个部分类文件,方法访问说明符是'内部'。



在运行应用程序时,它显示404错误并且表示找不到文件。



这是一个MVC项目。仅托管项目1。当我运行应用程序时,它指向项目1.然后,如果文件路径出错,如何在项目2中指定.cs文件的文件路径?



或者是否需要检查其他内容?



我尝试过的事情:



我已经逐一尝试了以下所有内容:



1.将jquery ajax中的type属性从POST更改为GET。

2.为函数添加[WebMethod]属性,并将访问说明符从internal更改为public。

3.运行时应用程序,动态更改文件路径,但无法识别实际文件路径应该是什么?

Hi All,

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

PROBLEM

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?

推荐答案

为什么不尝试在控制器内创建一个动作方法。然后将ajax调用指向。

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


这篇关于如何在.NET中的同一解决方案中调用来自不同项目的.cs文件中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆