本文介绍了找一个模板错误,当我尝试这样做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用asp.net MVC 3,我不断收到这个错误,因为我没有使用一个模板,我不明白。
我有这在我的局部视图
@model ViewModels.FormViewModel < DIV =标签-1>
@ Html.TextBoxFor(X => x.Due.ToShortDateString())
< / DIV>
在我的视图模型
公共类FormViewModel
{
公众的DateTime由于{搞定;组; }
公共FormViewModel()
{
DUEDATE = DateTime.UtcNow;
}
}
和我得到这个错误
解决方案
Should be like this:
@Html.TextBoxFor(x => x.Due)
And if you want some format for this date:
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime Due { get; set; }
and then:
@Html.EditorFor(x => x.Due)
of if you really want to use this .ToShortDateString()
method you need to use a non-strongly typed helper (obviously that's something I would recommend against):
@Html.TextBox("Due", Model.Due.ToShortDateString())
这篇关于找一个模板错误,当我尝试这样做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!