我正在像这样从ajax调用传递viewModel:
$.ajax("url", {
data: JSON.stringify({ vm: ko.toJS(ko.utils.unwrapObservable(window.viewModel)) }),
type: "POST",
async: performAsyncCall !== undefined ? performAsyncCall : true,
contentType: "application/json",
dataType: "json",
success: function (result) {
//Code here
},
error: function (error) {
//Code here
},
complete: function () {
//Code here
}
});
我的控制器方法(使用mvc 4)是这样的:
[HttpPost]
public ActionResult Method(CustomViewModel vm)
{
//Code here
}
window.viewModel(在javascript代码上)具有一个称为CreationDate的属性,该属性等于CustomViewModel(在c#代码上)也具有CreationDate属性的一个属性。在从客户端发布到服务器之前,CreationDate具有以下值(上午6:48):
但是在服务器上,相同的属性具有此值(上午2:48):
我需要客户的价值,但我没有发现价值如何变化,有人可以帮助我吗?
c#参考方案
发送TimeZone偏移量,您将知道用户的时间偏移量是多少。在JavaScript getTimezoneOffset()
对象上使用Date
。 Documentation
如果您不想更改模型,则只需在操作方法中添加其他参数即可:
[HttpPost]
public ActionResult Method(CustomViewModel vm, int timezoneOffset)
{
//Code here
}
在JS中:
var toSend = ko.toJS(ko.utils.unwrapObservable(window.viewModel));
$.ajax("url", {
data: JSON.stringify({ vm: toSend, timezoneOffset: toSend.CreationDate.getTimezoneOffset() / 60 }),
type: "POST",
async: performAsyncCall !== undefined ? performAsyncCall : true,
contentType: "application/json",
dataType: "json",
success: function (result) {
//Code here
},
error: function (error) {
//Code here
},
complete: function () {
//Code here
}
});
当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…
Mongo汇总 - javascript我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …
jQuery DataTable TableTool在IE和Firefox中不起作用 - c#我在MVC4 ASP.NET Web应用程序中使用Jquery DataTable TableTool。导出到Excel和PDF可以与Chrome完美配合。但是不能在IE和FireFox中使用。我的代码如下 dom: 'T<"clear">lfrtip', tableTools: { "sSwfP…
提交表单后显示模式对话框 - php提交下载文件后,我有一张表格。我要自动而不是自动下载文件..以显示模态对话框并显示下载链接。<form name="softwareform" id="softwareform" action="../downloadlink.php" method="POST" alig…
DataSourceTransactionManager和JndiObjectFactoryBean和JdbcTemplate的用途是什么? - java以下的用途是什么:org.springframework.jdbc.core.JdbcTemplate org.springframework.jdbc.datasource.DataSourceTransactionManager org.springframework.jndi.JndiObjectFactoryBean <tx:annotatio…