asp.net-mvc-3 – MVC3 Html.EditorFor在我的视图中不渲染任何东
发布时间:2020-12-16 10:00:56 所属栏目:asp.Net 来源:网络整理
导读:public class RegisterViewModel{ //Plain POCO Properties public RegisterModel RegisterModel { get; set; } //Meant to be used in SelectLists. public IEnumerableCityModel Cities { get; set; } public IEnumerableCountryModel Countries { get; se
public class RegisterViewModel { //Plain POCO Properties public RegisterModel RegisterModel { get; set; } //Meant to be used in SelectLists. public IEnumerable<CityModel> Cities { get; set; } public IEnumerable<CountryModel> Countries { get; set; } } 以下是这些课程: public class RegisterModel { [Required] [Display(Name = "Usuario")] public string UserName { get; set; } [Required] [DataType(DataType.EmailAddress)] [Display(Name = "Correo")] public string Email { get; set; } [Required] [StringLength(100,ErrorMessage = "Su {0} debe tener al menos {2} caracteres.",MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Contrase?a")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirme Su Contrase?a")] [Compare("Password",ErrorMessage = "Sus contrase?as no son las mismas.")] public string ConfirmPassword { get; set; } [Required] [Display(Name = "Nombre")] public string Nombre { get; set; } [Required] [Display(Name = "Apellido")] public string Apellido { get; set; } [Required] [Display(Name = "Direccion")] public string Address { get; set; } [Required] [Display(Name = "Telefono Fijo")] public string Telephone { get; set; } [Required] [Display(Name = "Celular")] public string MobilePhone { get; set; } [Required] [Display(Name = "Fecha de Nacimiento")] public DateTime DateOfBirth { get; set; } [Required] [Display(Name = "Soy:")] public bool Sex { get; set; } [Required] [Display(Name = "Carnet")] public int Carnet { get; set; } } public class CityModel { [HiddenInput(DisplayValue = false)] public int CityId { get; set; } [Required] [Display(Name = "Ciudad")] public string Name { get; set; } } public class CountryModel { [HiddenInput(DisplayValue = false)] public int CountryId { get; set; } [Required] [Display(Name = "Pais")] public string Name { get; set; } } 以下是我在视图中调用RegisterViewModel的方法: @model Foodiggly.WebUI.Models.RegisterViewModel @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>RegisterViewModel</legend> @Html.EditorForModel() <p> <input type="submit" value="Create" /> </p> </fieldset> } 是否导致此错误,因为我的ViewModel本身没有任何注释?我在哪里可以正式阅读这个?我在网上找到的只是偶尔的博客,但他们在网上提到了简单的模型,而不是那些与其他对象有关系的模型.典型的外国关键国家与人际关系. 有任何想法吗? 解决方法
视图模型RegisterViewModel没有任何“简单”属性,并且MVC框架不呈现复杂属性,除非我们告诉它如何呈现它们.我们必须为EditorFor帮助器创建DisplayFor和编辑器模板的显示模板.有关详细信息,请查看
ASP.NET MVC 2 Templates.另一个
link.
将EditorTemplates放在文件夹中 ~/Views/Shared/EditorTemplates or ~/Views/ControlerName/EditorTemplates RegisterModel.cshtml @model RegisterModel @Html.LabelForFor(model => model.UserName) @Html.EditorFor(model => model.UserName) @Html.LabelForFor(model => model.Email) @Html.EditorFor(model => model.Email) ... ... CityModel.cshtml @model CityModel @Html.LabelForFor(model => model.CityId) @Html.EditorFor(model => model.CityId) @Html.LabelForFor(model => model.Name) @Html.EditorFor(model => model.Name) CountryModel.cshtml @model CountryModel @Html.LabelForFor(model => model.CountryId) @Html.EditorFor(model => model.CountryId) @Html.LabelForFor(model => model.Name) @Html.EditorFor(model => model.Name) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET MVC 3不显眼的客户端验证
- asp.net-mvc – ASP.NET MVC,强类型视图,部分视图参数毛刺
- asp.net-mvc – “挑战”一词代表什么?
- asp.net-mvc – 在OnActionExecuting事件中更改模型
- asp.net-mvc – ASP.NET MVC – 本地化路由
- asp.net-mvc – Visual Studio在剃刀语句中显示语法错误但有
- asp.net-mvc-4 – 如何在ASP.NET MVC 4中使用免费的CSS模板
- asp.net – asp服务器错误’无法加载文件或程序集’,但程序
- 将.net核心连接到SSAS
- asp.net-mvc – ASP.NET MVC2母版页 – 服务器端脚本无法渲
推荐文章
站长推荐
- asp.net-mvc – 如何在razor中添加角度标签到htm
- asp.net-mvc – ASP.NET MVC页面/子页面路由
- asp.net-mvc – 将ASP.NET应用程序部署到多个EC2
- ASP.NET Web API 2:通过本机移动(iOS)应用程序与
- asp.net – 如何使用jquery或jscript触发单击按钮
- asp.net-mvc – 什么是Owin rememberBrowser做什
- ASP.NET 页面双向静态化
- asp.net – 为什么Web API请求的正文读取一次?
- 简单探讨一下.NET Core 3.0使用AspectCore的新姿
- asp.net-mvc-3 – MVC 3 – 比较属性 – 在客户端
热点阅读