2017-08-08 47 views
0

我有兩個項目Asp.net CoreAsp.net Mvc。 我魔杖與angualrjs發送數據從Asp.net核心到Asp.net Mvc與angualrjs

發送從第一個項目(Asp.net Core)到第二個項目(Asp.net Mvc)數據,當我運行兩個項目,我的問題是,當我想從Asp.net Core發佈模型ActionResultAsp.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在第二projcet(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; } 
} 

我怎樣才能解決這個問題?

+0

你能告訴你的'TblFishCar model'類?此外,請參閱此答案 - https://stackoverflow.com/questions/30957248/how-to-send-post-in-angularjs-with-multiple-params/30957308#30957308 – Sajal

+0

是編輯我的帖子 –

+0

更改'Guid'爲模型類中的'string'並從method參數中移除'[FromBody]'。稍後可以在方法體中將字符串強制轉換爲GUID(如果需要的話!)。 – Sajal

回答

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>