毫秒正在由一个ASP.NET MVC隐藏输入元素截断 [英] Milliseconds are being truncated by an ASP.NET MVC Hidden Input element

查看:109
本文介绍了毫秒正在由一个ASP.NET MVC隐藏输入元素截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个观点,即呈现一个项目列表,每个项目都包含一个日期属性。

I have a View that renders a list of items, and each item contains a Date property.

<%:Html.HiddenFor(m => m.Items[j].Date)%>

一个其他一些性能被隐藏或显示,并且用户能够进入针对任何项的评论,并保存这些评论到数据库中。这是一个批量编辑类型视图。

A number of other properties are hidden or shown, and the user is able to enter comments against any item and save these comments to the database. It's a 'bulk edit' type View.

我用之前良好的效果这些意见,而是因为它呈现这样我在与日期属性问题

I've used these Views before to good effect, but I'm having a problem with the Date property because it renders thus

<input name="Items[3].Date" type="hidden" value="3/05/2012 11:56:48 AM" />

的问题是,我需要使用的日期时间作为此数据项的主键的一部分。我可以截断毫秒在数据库中,以允许匹配但不保证将只有每秒一个数据点。

The problem is that I need to use the DateTime as a part of the primary key for this data item. I could truncate the milliseconds in the database to allow the match but there is no guarantee that there will only be one data point per second.

我如何确保我的的DateTime 隐藏输入字段保留了所有的财产的信息,包括毫秒分量?

How do I ensure that the hidden input field for my DateTime retains all of the property's information, including the milliseconds component?

推荐答案

好你真的需要使用

<%:Html.HiddenFor(m => m.Items[j].Date)%>

为什么不只是保持简单

why not just keep it simple

<input type="hiddeh" name="Items[<%:j%>].Date" value="<%:model.Items[j].Date.ToString("dd/MM/yy/ HH:mm:ss.fffff")%>"/>

这篇关于毫秒正在由一个ASP.NET MVC隐藏输入元素截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆