我在我的項目中有一個計時器,當我停止計時器值應該被保存到數據庫,但我無法從JavaScript到homecontroller獲取定時器的值。如何從JavaScript獲得價值到homecontroller?
我的JavaScript是:
<script type="text/javascript">
document.getElementById("starttime").innerHTML = ((hour<=9) ? "0"+hour : hour) + " : " + ((min<=9) ? "0" + min : min) + " : " + sec;
.
.
.
.
.
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#End").click(function() {
$.ajax({ url: '/Home/SaveAnsDetails?classs=' + ($("#txtClass").val())
+ '&ExamDate=' + ($("#ExamDate").val())
+ '&ddd=' + ($("#starttime").val()),<!--timer value starttime is passed to ddd-->
type: "Post",
dataType: "json",
success: function (message) {
alert(message);
}
});
});
});
</script>
<div id="starttime" style="font-size:large; "></div>
HomeController的編碼是
[ActionName("SaveAnsDetails")]
public ContentResult SaveAnsDetails(ModelGridAllFeatures model, IList<VW_Grid_Answer1> ds, string ExamDate, string ddd)
{
}
DDD從開始時間(定時器值)獲得。當我在homecontroller中獲得ddd值時,它包含一個空值。
任何想法?
我不確定此參數是否爲「ModelGridAllFeatures模型」,但您是否相應地爲Examdate獲取了值? –