【问题标题】:Send ASPX.net attribute towards angular in the backend在后端向 Angular 发送 ASPX.net 属性
【发布时间】:2016-10-13 17:22:28
【问题描述】:

如何连接'index.aspx.cs - public string getContactID() { return 1; }' 到 app.component.ts

这个事件需要任何方法都可以。

整个项目都在 Visual Studio 2015 Web Api 中


app\app.component.ts

SomethingClick() {
     ID:number = 'index.aspx.cs'.getContactID();
}

索引.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="CA_CopyLine.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
     <base href="/"/>
     <title>Angular 2 QuickStart</title>
     <meta charset="UTF-8"/>
     <meta name="viewport" content="width=device-width, initial-scale=1"/>
     <link rel="stylesheet" href="styles.css"/>

     <!-- 1. Load libraries -->
      <!-- Polyfill(s) for older browsers -->
     <script src="https://unpkg.com/core-js/client/shim.min.js"></script>

     <script src="https://unpkg.com/zone.js@0.6.21?main=browser"></script>
     <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
     <script src="https://unpkg.com/systemjs@0.19.27/dist/system.src.js"> 
</script>

     <!-- 2. Configure SystemJS -->
     <script src="systemjs.config.js"></script>
     <script>
       System.import('app').catch(function(err){ console.error(err); });
     </script>
</head>
<body>
    <my-app></my-app>
</body>
</html>

索引.aspx.cs

public partial class index     {

    [WebMethod]
    public string getContactID()
    {
        return 1;
    }
}

app\app.component.ts

 import { Component } from '@angular/core';
 @Component({
     selector: 'my-app',
     templateUrl: './app/app.component.html',
     styleUrls: ['./app/app.component.css']

 })
 export class AppComponent { }

SomethingClick() {
     ID:number = 'index.aspx.cs'.getContactID();
}

【问题讨论】:

  • 如果您使用 Web API,您可能希望实际使用 Web API(通过 ApiController)而不是 WebMethod Web 服务。
  • 问题是,这个项目是一个 Web API,aspx 用于使用 DLL 文件

标签: c# asp.net angularjs angular


【解决方案1】:

您必须对 webmethod 进行 http 调用以获取详细信息。此外,您还需要将 WebMethod 设为静态。请通过此link 获取更多信息。虽然在链接调用中是由 jquery 进行的,但这个概念也与 angular js 相同。

从 component.ts 向 index.aspx\getContactID 发起 http 调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-07
    • 2021-03-03
    • 2019-06-04
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2019-07-19
    • 2021-08-17
    相关资源
    最近更新 更多