Asp.net MVC不显示模板编辑
我有课程:
public class PersonDetailsModel
{
public string FistName
{
get;
set;
}
public string LastName
{
get;
set;
}
public string Email
{
get;
set;
}
}
public class RegisterCoupleModel
{
public PersonDetailsModel Groom
{
get;
set;
}
public PersonDetailsModel Bride
{
get;
set;
}
public string UrlKeyword
{
get;
set;
}
public string ReCaptcha
{
get;
set;
}
}
共享文件夹> EditorTemplates
PersonDetailsModel.cshtml
@model BindSolution.AndMarried.ViewModel.PersonDetailsModel
<div class="editor-label">
@Html.LabelFor(m => m.FistName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.FistName)
@Html.ValidationMessageFor(m => m.FistName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.LastName)
@Html.ValidationMessageFor(m => m.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Email)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.Email)
@Html.ValidationMessageFor(m => m.Email)
</div>
在我看来:
@Html.EditorForModel()
仅显示 UrlKeyword
和 ReCapcha
字段!
为什么 Asp.net MVC 不使用共享文件夹中的模板来显示我的嵌套类型 PersonDetailsModel
?
I have the classes:
public class PersonDetailsModel
{
public string FistName
{
get;
set;
}
public string LastName
{
get;
set;
}
public string Email
{
get;
set;
}
}
public class RegisterCoupleModel
{
public PersonDetailsModel Groom
{
get;
set;
}
public PersonDetailsModel Bride
{
get;
set;
}
public string UrlKeyword
{
get;
set;
}
public string ReCaptcha
{
get;
set;
}
}
folder Shared > EditorTemplates
PersonDetailsModel.cshtml
@model BindSolution.AndMarried.ViewModel.PersonDetailsModel
<div class="editor-label">
@Html.LabelFor(m => m.FistName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.FistName)
@Html.ValidationMessageFor(m => m.FistName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.LastName)
@Html.ValidationMessageFor(m => m.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Email)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.Email)
@Html.ValidationMessageFor(m => m.Email)
</div>
In my View:
@Html.EditorForModel()
Only the UrlKeyword
and ReCapcha
fields are displayed!
Why Asp.net MVC not use templantes in shared folder to display my nested type PersonDetailsModel
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你知道,你可以刚刚编辑你的其他问题。 :)
无论如何,我认为这不会起作用。您要么需要自己控制整个模板,要么让 MVC 自己完成这一切。 (我可能是错的)
为
RegisterCoupleModel
创建编辑器模板:或者您可以在
Groom
上使用[UIHint("PersonDetailsModel"]
属性和 ViewModel 中的Bride
属性请阅读 EditorForModel 了解这一切是如何进行的作品。
You know, you could have just edited your other question. :)
Anyway, i don't think that will work. You either need to control the entire template yourself, or let MVC do it all itself. (i could be wrong)
Create an editor template for
RegisterCoupleModel
:Or you could use a
[UIHint("PersonDetailsModel"]
attribute on yourGroom
andBride
properties in your ViewModel.Read up on the remarks section in EditorForModel for how this all works.