MVC.NET milliseconds get lost when using Html.hidden on a DateTime LastUpdated column for version tracking

后端 未结 5 2005
小鲜肉
小鲜肉 2021-01-12 15:30

Question in short:

How tot do this in MVC.NET?

Question in long version:

Im trying to use a DateTime column in a SQL Table for version tracking (this

5条回答
  •  一个人的身影
    2021-01-12 15:57

    I think the problem is that writing out the last update time into a hidden field like that will just do a ToString on the date which by default won't render out the milliseconds. You could try rendering out the timestamp as some absolute value such as ticks:

    <%= Html.Hidden("LastUpdate", Model.LastUpdate.Ticks) %>
    

    You can then reconstruct your datetime on the other side by converting the value back into a long & reconstructing the DateTime:

    var dt = new DateTime(Int64.Parse(ticks));
    

提交回复
热议问题