簡體   English   中英

使用angualr.js將數據從Asp.net核心發送到Asp.net Mvc

[英]Send data from Asp.net core to Asp.net Mvc with angualrjs

我有兩個項目Asp.net CoreAsp.net Mvc 我想用angualrjs將數據從第一個項目( Asp.net Core )發送到第二個項目( Asp.net Mvc

當我運行兩個項目時,我的問題是,當我想將模型從Asp.net CoreAsp.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM