0
我無法使用C#將HTML中的輸入類型TIME的值轉換爲MVC控制器中的TimeSpan。 我使用Jquery發送輸入值。將HTML輸入時間轉換爲TimeSpan
<div class="row">
<div class="col-md-6">
<label>Hora inicio: </label><input type="time" class="form-control" ng-model="hora.inicioc" />
</div>
<div class="col-md-6">
<label>Hora fin: </label><input type="time" class="form-control" ng-model="hora.finc" />
</div>
</div>
和我的jQuery是:
$scope.AddReg = function() {
AddProduccion();
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: 'http://localhost:2713/Produccion/AgregarProduccion/',
contentType: "application/json; charset=utf-8",
async: true,
//json object to sent to the authentication url
data: JSON.stringify({dp : $scope.materiales, p :$scope.produccion}),
success: function() {
alert("Se agregó registro de produccion");
}
})
};
而做到這一點之前,我推了NG-模型對象的數組來用jQuery發送。
var AddProduccion = function() {
$scope.produccion.push(
{
hora_inicio_congelacion: $scope.hora.inicioc,
hora_fin_congelacion: $scope.hora.finc,
hora_inicio_deshielo: $scope.hora.iniciod,
hora_fin_deshielo: $scope.hora.find,
hora_registro: "",
total_producido: 5,
total_merma: 5
}
);
};
而我的控制器是gettig兩個對象列表。
[HttpPost]
public ActionResult AgregarProduccion(List<DetalleProduccionBolsasViewModel> dp, List<PBolsasModel> p)
在我的PBolsasModel是
public class PBolsasModel
{
public System.TimeSpan hora_inicio_congelacion { get; set; }
public System.TimeSpan hora_fin_congelacion { get; set; }
public System.TimeSpan hora_inicio_deshielo { get; set; }
public System.TimeSpan hora_fin_deshielo { get; set; }
public System.DateTime hora_registro { get; set; }
public double total_producido { get; set; }
public double total_merma { get; set; }
}
我已經嘗試設置hour_inicio_congelacion,hora_fin_congelacion爲字符串,然後將它們的,但我得到一個錯誤,因爲我從視圖中所獲得的價值都沒有將其轉換爲TimeSpan的格式。我也想哭了。
你在其中一個屬性中有什麼價值(例如:hora_inicio_congelacion)? – Shyju
「1970-01-01T21:03:00.000Z」這種時間格式 – MisaelGaray