[英]Send data from Asp.net core to Asp.net Mvc with angualrjs
我有兩個項目Asp.net Core
和Asp.net Mvc
。 我想用angualrjs將數據從第一個項目( Asp.net Core
)發送到第二個項目( Asp.net Mvc
)
當我運行兩個項目時,我的問題是,當我想將模型從Asp.net Core
到Asp.net Mvc
ActionResult
時,此ActionResult
沒有價值。
Angularjs在第一個項目( Asp.net Core
)中:
$rootScope.PrintCArd2 = function () {
$scope.TblFishCar = {};
$scope.TblFishCar.IdFish = $rootScope.TblFishCarIdFish;
$http.post("http://localhost:61779/Report/GetFishReport", $scope.TblFishCar).then(function (result) {
alert("Ok2");
},
function (e) {
alert("warning"+e);
});
};
第二個項目中的ActionResult( Asp.net Mvc
):
public class ReportController : Controller
{
[System.Web.Http.HttpPost]
public ActionResult GetFishReport([FromBody]TblFishCar model)
{
//do something
return PartialView("_ShowReport");
}
}
angularjs調用公共ActionResult GetFishReport([FromBody]TblFishCar model)
但是該模型沒有價值。
TblFishCar:
public partial class TblFishCar
{
public Guid IdFish { get; set; }
public int ShFish { get; set; }
public string DateFish { get; set; }
}
我怎么解決這個問題?
查看瀏覽器的開發人員工具以查看實際錯誤。 另外,您還應該在MVC應用中啟用cross origin requests
:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="*" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<!--<remove name="OPTIONSVerbHandler" />-->
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.