Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Milliseconds are being truncated by an ASP.NET MVC Hidden Input element

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.

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

like image 753
Kirk Broadhurst Avatar asked Dec 31 '25 19:12

Kirk Broadhurst


1 Answers

well do you really need to use

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

why not just keep it simple

<input type="hidden" name="Items[<%:j%>].Date" value="<%:model.Items[j].Date.ToString("dd/MM/yy/ HH:mm:ss.fffff")%>"/>
like image 200
Parv Sharma Avatar answered Jan 02 '26 14:01

Parv Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!