2016-06-24 2 views
0

2つのパラメータを持つアクションのデータを投稿したいと思います。私はasp.net mvc 5アプリケーションで角度2を使用しています。2つのパラメータを渡す角2のポストメソッド

public ActionResult Login(string returnUrl, UserLogin _user) 
{ 

    return RedirectToAction("ExternalSignIn", new { returnUrl = returnUrl, userEmail = _user.Email }); 

} 
+0

'this.http.post( '/ Account/Login'、JSON.stringify([this.returnUrl、this.email]))。subscribe();' –

答えて

3

まず、以下のあなたがインポートされます

import { Http, Headers } from 'angular2/http'; 

次に、このサービス・コールのための

let url = 'base api url/Account/Login'; 
let data = { 
    "returnUrl": this.returnUrl, 
    "email": this.email 
}; 
let body = JSON.stringify(data) 
let head = new Headers({ 
    'Content-Type': 'application/json' 
}); 

this.http.post(url, body , {headers : head}) 
    .map(res => res.json()) 
    .subscribe((data:any) => { 
     //subscribe actions 
    }); 
1

床:フロア= {ID:0、名前: ""、 floorNumber:0、addressNumber: ""、floorTypeid:0}; floorUnit:FloorUnit = {id:0、floorID:0、unitID:0、addressNumber: ''、unitCost:0、standardPrice:0、taxTermid:0、imageUrl: ''、planUrl: ''、isAvailable:true、isTemperoryBooking :false、isNotReleased:false};

const floorUnitAddURL = "api/floorunit/AddFloorUnit";

// AddFloorUnit(){ IF(this.validationService.Validate(this.floorUnitForm、this.floorUnitFormErrors、this.floorUnitValidationMessages))

{を次のように配列することにより、同じPOSTメソッドでは2つのクラスオブジェクトを渡すことができ
 this.apiService.post(floorUnitAddURL, [this.floorUnit, this.floor], true).subscribe(
      res => { 
       var data: any = res; 
       if (data && data.status.success) { 
        this.notificationService.NotifyError("Success", data.status.displayMessage, "success"); 
        //this.ResetPropertyForm(); 
       } 
       else 
        this.notificationService.NotifyError("Error", data.status.displayMessage, "warning"); 
      }, 
      err => { 
       this.notificationService.NotifyError("Error", "Error Occured.", "warning"); 
      }); 
    } 
}; 

とWeb APIの方法で

を持つ2つの別個のパラメータ[HttpPost( "AddFloorUnit")] 公共化するJsonResultポスト([FromBody] FloorUnitDTO floorUnit、[FromBody] FloorDTO床) { try { Floor updateFloor = Mapper.Map(floor); Proxy.SetBaseEntityProperties(Request、updateFloor、true); _floorService.UpdateFloor(updateFloor);

  FloorUnit newfloorUnit = Mapper.Map<FloorUnit>(floorUnit); 
      Proxy<FloorUnit>.SetBaseEntityProperties(Request, newfloorUnit); 
      _floorUnitService.AddFloorUnit(newfloorUnit); 
      return Json(ErrorHandle<FloorUnit>.GetSuccessMessage(null)); 
     } 
     catch (Exception ex) 
     { 
      Log4netLogger<FloorUnit>.Error(Constants.ExceptionPolicy.BusinessLogic, ex); 
      return Json(ErrorHandle<FloorUnit>.GetInsertErrorMessage(ErrorCodes.FloorUnitInsertError, typeof(FloorUnit).Name)); 
     } 
    } 
関連する問題