[英]Send data from Asp.net core to Asp.net Mvc with angualrjs
I have two projects Asp.net Core
and Asp.net Mvc
. 我有两个项目
Asp.net Core
和Asp.net Mvc
。 I wand to send data from the first project( Asp.net Core
) to the second project( Asp.net Mvc
) with angualrjs 我想用angualrjs将数据从第一个项目(
Asp.net Core
)发送到第二个项目( Asp.net Mvc
)
When i run two projects ,my problem is that when I want to post Model from Asp.net Core
to ActionResult
in Asp.net Mvc
, this ActionResult
doesn't have value. 当我运行两个项目时,我的问题是,当我想将模型从
Asp.net Core
到Asp.net Mvc
ActionResult
时,此ActionResult
没有价值。
Angularjs in first project( Asp.net Core
): 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 in second projcet( Asp.net Mvc
): 第二个项目中的ActionResult(
Asp.net Mvc
):
public class ReportController : Controller
{
[System.Web.Http.HttpPost]
public ActionResult GetFishReport([FromBody]TblFishCar model)
{
//do something
return PartialView("_ShowReport");
}
}
angularjs calls public ActionResult GetFishReport([FromBody]TblFishCar model)
but model doesn't has value. angularjs调用公共
ActionResult GetFishReport([FromBody]TblFishCar model)
但是该模型没有价值。
TblFishCar: TblFishCar:
public partial class TblFishCar
{
public Guid IdFish { get; set; }
public int ShFish { get; set; }
public string DateFish { get; set; }
}
How can i solve this problem? 我怎么解决这个问题?
Look at the developer tools of the browser to see the real errors. 查看浏览器的开发人员工具以查看实际错误。 Also you should enable
cross origin requests
in your MVC app: 另外,您还应该在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.