前端之家收集整理的这篇文章主要介绍了
Angular4 & MVC方法调用,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参考
public class HomeController : DSController
{
[HttpGet]
public JsonResult GetUserAccount(string valu)
{
return new JsonResult()
{
Data= GetUserSystemRecordDTO(valu)
};
}
}
import { Injectable } from '@angular/core';
import { Http,Response,Headers,URLSearchParams,RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { HttpParams } from '@angular/common/http';
GetUserAccount(name:string): Observable<Article[]> {
const url = "http://localhost:22294/home";
const headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'});
const paras = new URLSearchParams();
paras.append('valu','xxx' );
const options = new RequestOptions({ headers: headers,params:paras });
return this.http.get(this.articleUrl+"/GetUserAccount",options).subscribe(
data => {
alert('ok');
},error => {
console.log(JSON.stringify(error.json()));
});
}