我有两个项目Asp.net Core
和Asp.net Mvc
。
我使用angualrjs将数据从第一个项目(Asp.net Core
)发送到第二个项目(Asp.net Mvc
)
当我运行两个项目时,我的问题是,当我想在Asp.net Core
中将模型从ActionResult
发布到Asp.net Mvc
时,此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调用public 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; }
}
我该如何解决这个问题?
答案 0 :(得分:1)
查看浏览器的开发人员工具以查看真正的错误。
您还应该在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>