投稿時にAngularjsを使用してオブジェクトをasp mvcコントローラに送信しようとしましたが、値はnullになります。
ここに何がありますか?
マイコントローラ:
public class RelatorioIndiceController : Controller
{
public ActionResult Index()
{
return View();
}
public JsonResult GerarRelatorio(RelatorioFiltroPesquisa filtro)
{
throw new NotImplementedException();
}
}
マイパラメータクラス:
public enum TipoRelatorio
{
IndiceCapacidade,
ImpactoMedio,
TempoMedio
}
public class RelatorioFiltroPesquisa
{
public TipoRelatorio TipoRelatorio { get; set; }
public string NomeRelatorio { get; set; }
public string Data { get; set; }
}
そして、私の意見:私は、オブジェクトが同じプロパティ名と、それらを持っている場合はチェックしました
<div ng-app="mainApp" id="body">
<div ng-controller="myCtrl" id="form">
<div class="radio">
<label>
<input type="radio" ng-model="Filtro.TipoRelatorio" value="0" name="TiposRelatorio" />
Índice Capacidade
</label>
</div>
<div class="radio">
<label>
<input type="radio" ng-model="Filtro.TipoRelatorio" value="1" name="TiposRelatorio" />
Impacto Médio
</label>
</div>
<div class="radio">
<label>
<input type="radio" ng-model="Filtro.TipoRelatorio" value="2" name="TiposRelatorio" />
Tempo Médio
</label>
</div>
<div class="input-group">
<label>Nome Relatório</label>
<input type="text" ng-model="Filtro.NomeRelatorio" class="form-control" />
</div>
<div class="input-group">
<label>Data</label>
<input type="text" ng-model="Filtro.Data" class="form-control" placeholder="__/__/____" />
</div>
<input type="submit" ng-click="Submit()" value="Gerar Relatório" />
</div>
</div>
@section scripts
{
<script src="~/Scripts/angular.min.js"></script>
<script>
angular.module('mainApp', [])
.controller('myCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.Submit = function() {
$http({
method: "GET",
url: "/RelatorioIndice/GerarRelatorio/",
params: { filtro: $scope.Filtro }
})
.success(function (data) {
console.log("Sucesso");
});
}
}]);
</script>
}
大丈夫です、コピーして貼り付けました。私はすでに別の類似の質問をここで確認していますが、この問題に関して私は助けてくれませんでした。
public JsonResult GerarRelatorio(FiltroRelatorioPesquisa filtro)
{
...
return Json(result, JsonRequestBehavior.AllowGet);
}
:あなたが要求を取得できるようにする必要があり、コントローラで
$scope.submit = function() {
$http.get("/RelatorioIndice/GerarRelatorio/", $scope.Filtro)
.success("Sucesso");
};
:このバージョンに変更
$http({
method: "GET",
url: "/RelatorioIndice/GerarRelatorio/",
params: { filtro: $scope.Filtro }
})
.success(function (data) {
console.log("Sucesso");
});
は、問題を解決した:それは問題が起こった
コードをコピーして貼り付けても問題なく動作しました。あなたはどこでヌルになっていますか? – Shyju
私はコントローラのアクションでnull値を取得しています。 – Trepid