[MVC][Shopping]Copy Will's Code
数据模型规划(Models)
//DisplayNameAttribute 指定属性的显示名称
[DisplayName("商品类别")]
//DisplayColumnAttribute 指定Name为外键列
[DisplayColumn("Name")]
public class ProductCategory
{
[Key]
public int Id { get; set; } [DisplayName("商品类别名称")]
[Required(ErrorMessage="请输入产品类别名称")]
public string Name { get; set; }
}
Notes:其中DisplayName属性,当我们使用Html.DisplayFor时会显示的标题文字,如:
@Html.LabelFor(model=>model.Name) 即会显示”商品类别名称",如果想要显示“商品类别”,即ProductCategory的DisplayName属性时该怎么操作呢?如下:
@model List<MvcShopping.Models.ProductCategory> <h2>@Html.DisplayNameFor(model => model[])</h2>
视图中的Model为List<ProductCategory>,model[0]为ProductCategory对象,所以@Html.DisplayNameFor(model[0])为“商品类别"。
即使区分[HttpPost]和[HttpGet]方法的签名也不能相同,如以下代码是不能通过编译的:
//会员注册页面
public ActionResult Register()
{
return View();
} //写入会员信息
[HttpPost]
public ActionResult Register()
{
return View();
}
[MVC][Shopping]Copy Will's Code的更多相关文章
- MVC学习6 学习使用Code First Migrations功能 把Model的更新同步到DB中
参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-th ...
- [.NET MVC进阶系列0x] EF Code First 数据迁徙(Migrations)
[因] Entity Framework中使用Code First模式进行开发时,数据库是基于Models中的类自动生成的(生成时间:第一次运行MVC项目时), 每次更改Models中类结构,重新编译 ...
- Spring 4 MVC example with Maven - [Source Code Download]
In this tutorial, we show you a Spring 4 MVC example, using Maven build tool. Technologies used : Sp ...
- Asp.Net MVC 常用开发方式之EF Code First
在我们的工作和学习当中,经常会遇到中小型项目,这些项目除了业务上的区别较大外,对于底层和数据访问,其实都差不多.记得以前做项目时,每次都要重复的写底层操作数据库的代码,不仅浪费时间,也无太大意思,后来 ...
- 关于在ASP.NET MVC 中使用EF的Code First的方式来读取数据库时的Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
今天在做一个小网站的时候遇到很多问题唉,我还是个菜鸟,懂的也不多,今天一个表单的提交按钮用不了,都弄了几个小时唉.不过最后还是搞定了,还有浏览器有开发人员选项,不然我都不知道我还要继续排查多久哦,今天 ...
- 【翻译】使用Visual Studio创建Asp.Net Core MVC (一)
This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio ...
- 005.Getting started with ASP.NET Core MVC and Visual Studio -- 【VS开发asp.net core mvc 入门】
Getting started with ASP.NET Core MVC and Visual Studio VS开发asp.net core mvc 入门 2017-3-7 2 分钟阅读时长 本文 ...
- Spring mvc解析
方案时间 ,写代码时间 ,解决技术难点时间 , 自测时间,解决bug时间 , 联调时间 ,数据库优化,代码走查1个接口:2个小时 把那个字段再复原回来,不然兼容性不强还有一个刷数据的接口 public ...
- CRUD using Spring MVC 4.0 RESTful Web Services and AngularJS
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
随机推荐
- mysql-SQL语法
细节查询:http://www.w3school.com.cn/sql/index.asp 1 DDL-data difinition lanuage数据定义语句 使我们有能力创建或删除表格,我们也可 ...
- HDU2586(tarjanLCA板子)
; int T, n, m; int f[maxn], vis[maxn], dis[maxn], ans[maxn]; vector<P> vc[maxn]; vector<int ...
- 题解报告:zoj 3261 Connections in Galaxy War(离线并查集)
Description In order to strengthen the defense ability, many stars in galaxy allied together and bui ...
- 使用PreparedStatement接口
- CGI和Servlet的比较
转载自:http://www.maxhis.info/java/cgi-vs-servlet/ 概括来说,CGI和Servlet可以完成相同的功能. CGI(Common Gateway Interf ...
- 在 Windows 7 中禁用IPv6协议/IPv6隧道
How to disable certain Internet Protocol version 6 (IPv6) components in Windows Vista, Windows 7 and ...
- android开发学习 ------- git - 将代码回滚到任意版本
不小心将一个东西错误提交到git - 远程仓库上 参考 https://www.cnblogs.com/wancy86/p/5848024.html 你的git可能关联了多个远程仓库,每个关联的代码 ...
- asp.net 线程批量导入数据,ajax获取执行状态
最近做了一个批量导入功能,长时间运行,没个反馈状态,很容易让人看了心急,产生各种臆想!为了解决心里障碍,写了这么个功能. 通过线程执行导入,并把正在执行的状态存入session,既共享执行状态,通过a ...
- ubuntu中mysql安装失败
在ubuntu中mysql安装失败后,卸载重新安装还是安装失败,之后找了资料说是卸载的不干净,然后进行下面操作,重新安装成功. 解决办法如下: sudo rm /var/lib/mysql/ -Rsu ...
- AJPFX总结private关键字
private关键字 什么是private关键字? 它是一个修饰符,代表私有的意思,它可以修饰成员变量和成员方法 private关键字的特点? ...