- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 knockout 模型,它正在为我的页面提供数据,并在保存时在客户端执行以下代码。
self.save = function() {
var tirerun = ko.mapping.toJSON(self.data());
$.ajax({
type: 'post',
url: "@Url.Action("SaveTireRunModel", "Events")",
data: tirerun,
success: function(result) {
if (!result.success) {
alert(result.error);
} else {}
}
});
};
然后它将以下 JSON 发布到我的服务器(来自 fiddler 并为简洁起见进行了裁剪)
带有以下http请求 header
POST http://localhost:63648/Events/SaveTireRunModel HTTP/1.1
Host: localhost:63648
Connection: keep-alive
Content-Length: 1975
Origin: http://localhost:63648
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://localhost:63648/Events/OutingDetails?outingID=010fd8a1-e3a5-e111-a660-f0def1589f4b
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: jstree_open=%232012%2C%23c914324c-4d9f-e111-a79b-0024e8a037d3%2C%23eb-e957-e111-9e70-d067e53b2ed6%2C%234d-c00e-e111-ad1c-0e6e17349d3e%2C%2357-c00e-e111-ad1c-0e6e17349d3e%2C%234d-c00e-e111-ad1c-0e6e17349d3e; jstree_load=; .ASPXAUTH=054DD21DC0A17DDDAAFC254500ED8D6B3299EAABF1FB647732618E956EF082880BBA0B52A59849D3362AA03EB1F27D28867B07CD8451E4E983D84365608AA145F8DF8D71C2481639E110EC31325EE27EA3281FA2EDB7AD31A744D2A9918BE6599DB97E489ED4598D2DF63C31E36E809A282CF96FFCE5ACAEF8308FEA3DF1C6DE50B2AA7299F9D9AF0C30CE867DCCA352; jstree_open=%232012%2C%233dcc4b9b-37a3-e111-a6d3-0026b99ca1da%2C%23eb-e957-e111-9e70-d067e53b2ed6%2C%2357-c00e-e111-ad1c-0e6e17349d3e%2C%23a2962e1b-45a5-e111-b9ac-f0def1589f4b; jstree_load=%2311a4611a-8851-e111-95c7-60d819fcced5%2C%23b89422a0-0d03-e011-99cb-d601d71f0fcf; jstree_select=%23010fd8a1-e3a5-e111-a660-f0def1589f4b
{"Comments":"RSTA Dwn 2 Holes (6)\r\nRF Spring to 35468\r\nCross Dwn to 47.9 (-0.2)","TireSetsList":[{"ID":"1","Value":"1"},{"ID":"2","Value":"2"},{"ID":"3","Value":"3"},{"ID":"4","Value":"4"},{"ID":"5","Value":"5"}],"LFShoulderTemp":245,"RFShoulderTemp":245,"LFOuterTemp":177,"LFMiddleTemp":null,"LFInnerTemp":200,"RFOuterTemp":177,"RFMiddleTemp":null,"RFInnerTemp":200,"LROuterTemp":177,"LRMiddleTemp":null,"LRInnerTemp":200,"RROuterTemp":177,"RRMiddleTemp":null,"RRInnerTemp":200,"LFInitialOuterWear":null,"LFInitialOuterMiddleWear":null,"LFInitialMiddleWear":null,"LFInitialInnerMiddleWear":null,"LFInitialInnerWear":null,"LFAfterOuterWear":null,"LFAfterOuterMiddleWear":null,"LFAfterMiddleWear":200,"LFAfterInnerMiddleWear":null,"LFAfterInnerWear":null,"RFInitialOuterWear":null,"RFInitialOuterMiddleWear":null,"RFInitialMiddleWear":null,"RFInitialInnerMiddleWear":null,"RFInitialInnerWear":null,"RFAfterOuterWear":null,"RFAfterOuterMiddleWear":null,"RFAfterMiddleWear":200,"RFAfterInnerMiddleWear":null,"RFAfterInnerWear":null,"LRInitialOuterWear":null,"LRInitialOuterMiddleWear":null,"LRInitialMiddleWear":null,"LRInitialInnerMiddleWear":null,"LRInitialInnerWear":null,"LRAfterOuterWear":null,"LRAfterOuterMiddleWear":null,"LRAfterMiddleWear":200,"LRAfterInnerMiddleWear":null,"LRAfterInnerWear":null,"RRInitialOuterWear":null,"RRInitialOuterMiddleWear":null,"RRInitialMiddleWear":null,"RRInitialInnerMiddleWear":null,"RRInitialInnerWear":null,"RRAfterOuterWear":null,"RRAfterOuterMiddleWear":null,"RRAfterMiddleWear":200,"RRAfterInnerMiddleWear":null,"RRAfterInnerWear":null,"LFInnerColdPressure":71,"LFInnerHotPressure":null,"RFInnerColdPressure":71,"RFInnerHotPressure":null,"LRInnerColdPressure":71,"LRInnerHotPressure":null,"RRInnerColdPressure":71,"RRInnerHotPressure":null,"LFColdPressure":61.5,"LFHotPressure":69.8,"RFColdPressure":61.5,"RFHotPressure":69.8,"LRColdPressure":61.5,"LRHotPressure":69.8,"RRColdPressure":61.5,"RRHotPressure":69.8,"TrackTemp":133}
但是当它进入我的行动时,模型完全无效。
public JsonResult SaveTireRunModel(TireRunViewModel tirerun)
{
tirerun.Save();
return Json(new { success = true });
}
我的模型类如下
public class TireRunViewModel
{
public TireRunViewModel()
{
}
public TireRunViewModel(Guid outingID)
{
//data access crud here
}
public string Comments { get; set; }
public List<SelectBoxModel> TireSetsList { get; set; }
public double? LFShoulderTemp { get; set; }
public double? RFShoulderTemp { get; set; }
public double? LFOuterTemp { get; set; }
public double? LFMiddleTemp { get; set; }
public double? LFInnerTemp { get; set; }
public double? RFOuterTemp { get; set; }
public double? RFMiddleTemp { get; set; }
public double? RFInnerTemp { get; set; }
public double? LROuterTemp { get; set; }
public double? LRMiddleTemp { get; set; }
public double? LRInnerTemp { get; set; }
public double? RROuterTemp { get; set; }
public double? RRMiddleTemp { get; set; }
public double? RRInnerTemp { get; set; }
public double? LFInitialOuterWear { get; set; }
public double? LFInitialOuterMiddleWear { get; set; }
public double? LFInitialMiddleWear { get; set; }
public double? LFInitialInnerMiddleWear { get; set; }
public double? LFInitialInnerWear { get; set; }
public double? LFAfterOuterWear { get; set; }
public double? LFAfterOuterMiddleWear { get; set; }
public double? LFAfterMiddleWear { get; set; }
public double? LFAfterInnerMiddleWear { get; set; }
public double? LFAfterInnerWear { get; set; }
public double? RFInitialOuterWear { get; set; }
public double? RFInitialOuterMiddleWear { get; set; }
public double? RFInitialMiddleWear { get; set; }
public double? RFInitialInnerMiddleWear { get; set; }
public double? RFInitialInnerWear { get; set; }
public double? RFAfterOuterWear { get; set; }
public double? RFAfterOuterMiddleWear { get; set; }
public double? RFAfterMiddleWear { get; set; }
public double? RFAfterInnerMiddleWear { get; set; }
public double? RFAfterInnerWear { get; set; }
public double? LRInitialOuterWear { get; set; }
public double? LRInitialOuterMiddleWear { get; set; }
public double? LRInitialMiddleWear { get; set; }
public double? LRInitialInnerMiddleWear { get; set; }
public double? LRInitialInnerWear { get; set; }
public double? LRAfterOuterWear { get; set; }
public double? LRAfterOuterMiddleWear { get; set; }
public double? LRAfterMiddleWear { get; set; }
public double? LRAfterInnerMiddleWear { get; set; }
public double? LRAfterInnerWear { get; set; }
public double? RRInitialOuterWear { get; set; }
public double? RRInitialOuterMiddleWear { get; set; }
public double? RRInitialMiddleWear { get; set; }
public double? RRInitialInnerMiddleWear { get; set; }
public double? RRInitialInnerWear { get; set; }
public double? RRAfterOuterWear { get; set; }
public double? RRAfterOuterMiddleWear { get; set; }
public double? RRAfterMiddleWear { get; set; }
public double? RRAfterInnerMiddleWear { get; set; }
public double? RRAfterInnerWear { get; set; }
public double? LFInnerColdPressure { get; set; }
public double? LFInnerHotPressure { get; set; }
public double? RFInnerColdPressure { get; set; }
public double? RFInnerHotPressure { get; set; }
public double? LRInnerColdPressure { get; set; }
public double? LRInnerHotPressure { get; set; }
public double? RRInnerColdPressure { get; set; }
public double? RRInnerHotPressure { get; set; }
public double? LFColdPressure { get; set; }
public double? LFHotPressure { get; set; }
public double? RFColdPressure { get; set; }
public double? RFHotPressure { get; set; }
public double? LRColdPressure { get; set; }
public double? LRHotPressure { get; set; }
public double? RRColdPressure { get; set; }
public double? RRHotPressure { get; set; }
public int? SetNumberLF { get; set; }
public int? SetNumberRF { get; set; }
public int? SetNumberLR { get; set; }
public int? SetNumberRR { get; set; }
public double? TrackTemp { get; set; }
public void Save()
{
//data access crud here
}
}
我可以采取什么措施来进一步解决此问题并找出我的模型未绑定(bind)的原因?
最佳答案
$.ajax 的默认内容类型方法是'application/x-www-form-urlencoded'
如果您想发送 JSON,则必须指定您要发送 JSON,否则模型绑定(bind)器将无法正常工作:
$.ajax({
type: 'post',
url: "@Url.Action("SaveTireRunModel", "Events")",
data: tirerun,
contentType: 'application/json',
success: function(result) {
if (!result.success) {
alert(result.error);
} else {}
}
});
您可能还需要使用以下方式“字符串化”数据:data: JSON.stringify(tirerun)
关于asp.net-mvc - 为什么我从 Knockout 提交的内容不能绑定(bind)到我的 MVC 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11050523/
我试图对 ASP.Net MVC 有一个高层次的理解,我开始意识到它看起来很像原始的 ASP 脚本。过去,我们将“模型”/业务逻辑代码组织到 VBScript 类或 VB COM 组件中。 当然,现在
我已经搜索了一段时间,但似乎找不到答案。 我想在我的旋转木马中显示一个计数器,左边是当前项目(工作),左边是项目总数。 我的代码:
. 最佳答案 Scott Gu 称这些为代码块。这就是我的看法。 http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax
我有一个使用 Visual Studio 2010/.net 4/VB 制作的网站。 我真的很喜欢我发现的 FAQ 系统的布局,因为它很简单,但它是经典的 asp。所以,显然,我不能包括我的母版页布局
好吧,对于你们许多人来说,这个问题可能有一个非常明显的答案,但它让我难住了。 我有一个 asp.net Web 表单,上面有两个控件(嗯,不止这两个,但我们将重点关注这些) - 第一个是 asp:dr
当我将 ASP.NET 复选框控件设置为 asp.net 更新面板的异步回发触发器时,EventName 属性是什么? 最佳答案 我相信它是 CheckedChanged。 关于asp.net - a
我有一个用经典 asp 编写的(巨大的)网站。现在我必须切换到 vb.net (razor)。有没有办法将这两个结合起来直到切换完成? 有没有办法让应用程序与经典的 asp 和 vb.net 一起工作
I am creating a products page, where the user selects an option in a radiobuttonlist for example, an
我最近将一个经典的 ASP 应用程序转换为 ASP.NET 3.5,但我觉得我的经典 ASP 版本要快一些(我不知道可能买家会后悔)。 所以你们能帮我解决这个问题吗,让我知道哪个更快,asp、asp.
从本周开始,我被要求开始学习如何使用 ASP 开发网站。我通过 XNA 对 C# 有一定的经验,所以这部分对我来说并不是什么麻烦。 我一直在关注Music Store Tutorial这需要我设置一个
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我想将一些表单变量发布到经典 ASP 页面中。我不想改变经典的 ASP 页面,因为需要完成大量的工作,以及消耗它们的页面数量。 经典的 ASP 页面需要将表单变量 Username 和 Userpas
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
在某种程度上,这可能是一个异端问题。我们有一个大型站点,其中许多页面仍在ASP中。通常,并没有真正动态的,而是包括(通过SSI或Server.Execute)定期重新生成的HTML块。看起来好像是一个
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我有一个遗留的 ASP 应用程序——在不久的某个时候——需要迁移到 ASP.Net 2.0(以与也在 2.0 中的其他应用程序兼容)。 对于这类事情是否有最佳实践,即作为第一步将当前 html、vbs
我目前在一家公司工作,该公司使用 ASP.NET Webforms 和旧 ASP 页面的组合进行 Web 开发。这对于他们当前的项目来说效果很好,但我想说服/建议他们切换到 ASP.NET MVC,因
我有一个经典的 asp 应用程序。我想将该页面的竞赛表格发布到 Asp.Net 表格。原因是我想在进入数据库之前使用我在 Asp.Net 页面中内置的大量逻辑进行验证,而我对 asp 不太了解。更不用
我知道在 ASP.NET MVC 中,您可以拥有移动 View 并执行类似 Index.mobile.cshtml 的操作。和 _Layout.mobile.cshtml并且服务器知道将这些 View
我需要从一些服务器端 c#.net 代码中调用经典 asp 页面上的 VBscript 函数 - 有谁知道一种干净的方法来做到这一点?在 .net 中重写函数不是一种选择。 我会再解释一下这个问题..
我是一名优秀的程序员,十分优秀!