[英]Can auto-implemented properties be bound?
I have a property in a complex object such as this:我在复杂的 object 中有一个属性,例如:
public string startHour
{
get
{
return StartTime != null ? ((DateTime) StartTime).ToString("%h") : "";
}
set { startHour = value; }
}
My question is: Can this be bound in a HiddenFor
to a form, and still post back?我的问题是:这可以在HiddenFor
中绑定到一个表单,并且仍然回发吗? Would look like this:看起来像这样:
@Html.HiddenFor(m => Model.startHour)
I'm asking this because I'm using automatic properties in a complex object in my model, and the complex object is returning null, so could this cause a problem? I'm asking this because I'm using automatic properties in a complex object in my model, and the complex object is returning null, so could this cause a problem?
I've looked up 100+ questions related to my problem, and afaik I'm doing everything right.我已经查找了 100 多个与我的问题相关的问题,而且我做的一切都是正确的。
Used private properties for auto-implemented properties, works perfectly now.将私有属性用于自动实现的属性,现在可以完美运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.