我一直在使用以下关于学习 MVC 4 和 Razor的Lynda.com 教程。我一直试图让显示的时间只显示小时、分钟,然后是 AM/PM。截至目前,屏幕仍包含秒数(如下所示):
我尝试像这篇关于 DateTime 的帖子那样格式化我的日期,但这没有用。现在,我在标题为“AuctionsController.vb”的控制器部分的函数中有以下代码,类似于这篇文章:
Function Auction() As ActionResult
Dim mainauction = New MVCAuction3.Models.Auctions
Dim ts As New TimeSpan(10, 0, 0)
mainauction.Title = "Example Auction"
mainauction.Description = "This is an example Auction"
mainauction.StartTime = DateTime.Now + ts
mainauction.EndTime = DateTime.Now.AddDays(7) + ts
mainauction.StartPrice = 1.0
mainauction.CurrentPrice = Nothing
ViewData("Auction") = mainauction
Return View()
End Function
这是 Razor 从“Auction.vbhtml”视图显示内容的方式:
<p>Start Time: @auction.StartTime.ToString() </p>
<p>End Time: @auction.EndTime.ToString()</p>
<p>Starting Price: @FormatCurrency(auction.StartPrice.ToString())</p>
编辑:
这就是我在模态文件中声明时间变量的方式:
Private Property x_StartTime As DateTime
Private Property x_EndTime As DateTime
Public Property StartTime() As DateTime
Get
Return x_StartTime
End Get
Set(value As DateTime)
x_StartTime = value
End Set
End Property
Public Property EndTime() As DateTime
Get
Return x_EndTime
End Get
Set(value As DateTime)
x_EndTime = value
End Set
End Property
我还尝试从“Auction.vhtml”视图中获取以下内容,不幸的是,这给了我服务器错误,指示“输入字符串的格式不正确”。:
<p>Start Time: @auction.StartTime.ToString("g") </p>
<p>End Time: @auction.EndTime.ToString("g")</p>
<p>Starting Price: @FormatCurrency(auction.StartPrice.ToString())</p>
我在没有格式化时间的 Razor 或 MVC 代码中做错了什么?任何帮助是极大的赞赏!