【Asp.net MVC ---杂七杂八】
@RenderSection
母模板:_mainLayout.cshtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title> @ViewBag.Title</title>
.................
@RenderSection("HeaderSection", false)
</head>
使用母模板:
@model 。。。。 @{
Layout = "~/Views/Shared/_mainLayout.cshtml";
ViewBag.Title = " 首页";
}
@section HeaderSection {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
function del(id){
.......
}
}
} function update(id){
..........
}
} </script>
}
Scripts.Render
@section HeaderSection {
@Scripts.Render("~/bundles/jqueryval")
BundleConfig.cs
using System.Web;
using System.Web.Optimization; namespace Keasy5.HouseRent.Web.AspMvc
{
public class BundleConfig
{
// 有关 Bundling 的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*")); // 使用要用于开发和学习的 Modernizr 的开发版本。然后,当你做好
// 生产准备时,请使用 http://modernizr.com 上的生成工具来仅选择所需的测试。
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*")); bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css")); bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
}
数据校验
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text; namespace ByteartRetail.DataObjects
{
#region Metadata Annotations
[MetadataType(typeof(CategoryDataObjectMetadata))]
public partial class CategoryDataObject
{
public override string ToString()
{
return this.Name;
}
} public class CategoryDataObjectMetadata
{
[Required(ErrorMessage="请输入商品分类名称", AllowEmptyStrings=false)]
[Display(Name="分类名称")]
public string Name { get; set; } [Required(ErrorMessage="请输入商品分类说明", AllowEmptyStrings=false)]
[Display(Name = "分类说明")]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
} [MetadataType(typeof(ProductDataObjectMetadata))]
public partial class ProductDataObject
{
public string CategoryName
{
get
{
if (this.Category == null)
return "(未分类)";
else
return this.Category.Name;
}
}
public override string ToString()
{
return this.Name;
}
} public class ProductDataObjectMetadata
{
[Required(ErrorMessage="请输入商品名称", AllowEmptyStrings=false)]
[Display(Name="商品名称")]
public string Name { get; set; } [Required(ErrorMessage = "请输入商品说明", AllowEmptyStrings = false)]
[DataType(DataType.MultilineText)]
[Display(Name = "商品说明")]
public string Description { get; set; } [Required(ErrorMessage = "请选择商品图片", AllowEmptyStrings=false)]
[Display(Name = "商品图片")]
public string ImageUrl { get; set; } [DataType(DataType.Currency, ErrorMessage="输入的数据必须是货币类型")]
[Required(ErrorMessage = "请输入单价", AllowEmptyStrings = false)]
[Display(Name = "单价")]
public decimal? UnitPrice { get; set; } [Display(Name="是否为推荐商品?")]
[Required(ErrorMessage="请设置该商品是否为推荐商品")]
public bool? IsFeatured { get; set; }
} [MetadataType(typeof(RoleDataObjectMetadata))]
public partial class RoleDataObject
{
public override string ToString()
{
return Name;
}
} public class RoleDataObjectMetadata
{
[Required(ErrorMessage="请输入角色名称")]
[Display(Name="角色名称")]
public string Name { get; set; } [Display(Name="角色描述")]
public string Description { get; set; }
}
#endregion #region Object Extenders
/// <summary>
/// 表示<c>QuerySpec</c>类型的扩展。
/// </summary>
public partial class QuerySpec
{
#region Public Fields
/// <summary>
/// 返回一个<c>QuerySpec</c>类型的值,该值表示一个空的<c>QuerySpec</c>值:仅查询
/// 并构建聚合根的数据传输对象。
/// </summary>
public static readonly QuerySpec Empty = new QuerySpec
{
Verbose = null
}; /// <summary>
/// 返回一个<c>QuerySpec</c>类型的值,该值表示需要查询并构建聚合根及其下各层的数据传输对象。
/// </summary>
public static readonly QuerySpec VerboseOnly = new QuerySpec
{
Verbose = true
};
#endregion #region Public Methods
public override string ToString()
{
return string.Format("Verbose={0}", Verbose ?? false);
}
#endregion
} /// <summary>
/// 表示一个提供了分页相关信息的数据传输对象。
/// </summary>
public partial class Pagination
{
#region Public Methods
public override string ToString()
{
return string.Format("PageSize={0} PageNumber={1} TotalPages={2}",
this.PageSize,
this.PageNumber,
this.TotalPages ?? );
}
#endregion
} public partial class UserDataObject
{
public override string ToString()
{
return this.UserName;
}
} public partial class SalesOrderDataObject
{
public string StatusText
{
get
{
if (this.Status != null && this.Status.HasValue)
switch (this.Status)
{
case SalesOrderStatusDataObject.Created:
return "新创建";
case SalesOrderStatusDataObject.Delivered:
return "已收货";
case SalesOrderStatusDataObject.Dispatched:
return "已发货";
case SalesOrderStatusDataObject.Paid:
return "已付款";
case SalesOrderStatusDataObject.Picked:
return "已提货";
default:
return null;
}
else
return null;
}
} public string DateCreatedText
{
get { return this.DateCreated == null ? "N/A" : this.DateCreated.Value.ToShortDateString(); }
} public string DateDispatchedText
{
get { return this.DateDispatched == null ? "N/A" : this.DateDispatched.Value.ToShortDateString(); }
} public string DateDeliveredText
{
get { return this.DateDelivered == null ? "N/A" : this.DateDelivered.Value.ToShortDateString(); }
} public int TotalLines
{
get { return this.SalesLines == null ? : this.SalesLines.Count; }
} public string IDText
{
get { return this.ID.Substring(, ) + "..."; }
} public string TotalAmount
{
get { return string.Format("{0:N2} 元", this.Subtotal); }
} public bool CanConfirm
{
get
{
return this.Status != null && this.Status == SalesOrderStatusDataObject.Dispatched;
}
} public override string ToString()
{
return this.ID;
}
}
#endregion #region View Models
public partial class UserAccountModel
{
public string ID { get; set; }
[Required(ErrorMessage="请输入用户名")]
[Display(Name="用户名")]
public string UserName { get; set; } [Required(ErrorMessage = "请输入密码")]
[DataType(DataType.Password)]
[Display(Name="密码")]
public string Password { get; set; } [Required(ErrorMessage = "请重新输入密码以便确认")]
[DataType(DataType.Password)]
[Display(Name = "确认密码")]
[Compare("Password", ErrorMessage = "确认密码与输入的密码不符")]
public string ConfirmPassword { get; set; } [Display(Name="电子邮件")]
[Required(ErrorMessage="请输入电子邮件")]
[DataType(DataType.EmailAddress, ErrorMessage="电子邮件格式不正确")]
public string Email { get; set; } [Display(Name="已禁用")]
public bool? IsDisabled { get; set; } [Display(Name="注册时间")]
[DataType(DataType.Date)]
public DateTime? DateRegistered { get; set; } [Display(Name = "注册时间")]
public string DateRegisteredStr
{
get { return DateRegistered.HasValue ? DateRegistered.Value.ToShortDateString() : "N/A"; }
} [Display(Name = "角色")]
public RoleDataObject Role { get; set; } [Display(Name = "角色")]
public string RoleStr
{
get
{
if (Role != null && !string.IsNullOrEmpty(Role.Name))
return Role.Name;
return "(未指定)";
}
} [Display(Name="最后登录")]
[DataType(DataType.Date)]
public DateTime? DateLastLogon { get; set; } [Display(Name = "最后登录")]
public string DateLastLogonStr
{
get { return DateLastLogon.HasValue ? DateLastLogon.Value.ToShortDateString() : "N/A"; }
} [Display(Name="联系人")]
[Required(ErrorMessage="请输入联系人")]
public string Contact { get; set; } [Display(Name = "电话号码")]
[Required(ErrorMessage = "请输入电话号码")]
[RegularExpression(@"((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)",
ErrorMessage="电话号码格式不正确")]
public string PhoneNumber { get; set; } [Display(Name = "联系地址 - 国家")]
[Required(ErrorMessage = "请输入国家")]
public string ContactAddress_Country { get; set; } [Display(Name = "联系地址 - 省/州")]
[Required(ErrorMessage = "请输入省/州")]
public string ContactAddress_State { get; set; } [Display(Name = "联系地址 - 市")]
[Required(ErrorMessage = "请输入市")]
public string ContactAddress_City { get; set; } [Display(Name = "联系地址 - 街道")]
[Required(ErrorMessage = "请输入街道")]
public string ContactAddress_Street { get; set; } [Display(Name = "联系地址 - 邮编")]
[Required(ErrorMessage = "请输入邮编")]
public string ContactAddress_Zip { get; set; } [Display(Name = "收货地址 - 国家")]
[Required(ErrorMessage = "请输入国家")]
public string DeliveryAddress_Country { get; set; } [Display(Name = "收货地址 - 省/州")]
[Required(ErrorMessage = "请输入省/州")]
public string DeliveryAddress_State { get; set; } [Display(Name = "收货地址 - 市")]
[Required(ErrorMessage = "请输入市")]
public string DeliveryAddress_City { get; set; } [Display(Name = "收货地址 - 街道")]
[Required(ErrorMessage = "请输入街道")]
public string DeliveryAddress_Street { get; set; } [Display(Name = "收货地址 - 邮编")]
[Required(ErrorMessage = "请输入邮编")]
public string DeliveryAddress_Zip { get; set; } public override string ToString()
{
return UserName;
} public static UserAccountModel CreateFromDataObject(UserDataObject d)
{
return new UserAccountModel
{
ID = d.ID,
UserName = d.UserName,
Password = d.Password,
Email = d.Email,
IsDisabled = d.IsDisabled,
DateRegistered = d.DateRegistered,
DateLastLogon = d.DateLastLogon,
Role = d.Role,
Contact = d.Contact,
PhoneNumber = d.PhoneNumber,
ContactAddress_City = d.ContactAddress.City,
ContactAddress_Street = d.ContactAddress.Street,
ContactAddress_State = d.ContactAddress.State,
ContactAddress_Country = d.ContactAddress.Country,
ContactAddress_Zip = d.ContactAddress.Zip,
DeliveryAddress_City = d.DeliveryAddress.City,
DeliveryAddress_Street = d.DeliveryAddress.Street,
DeliveryAddress_State = d.DeliveryAddress.State,
DeliveryAddress_Country = d.DeliveryAddress.Country,
DeliveryAddress_Zip = d.DeliveryAddress.Zip,
};
} public UserDataObject ConvertToDataObject()
{
return new UserDataObject
{
ID = this.ID,
UserName = this.UserName,
Password = this.Password,
IsDisabled = this.IsDisabled,
Email = this.Email,
DateRegistered = this.DateRegistered,
DateLastLogon = this.DateLastLogon,
Contact = this.Contact,
PhoneNumber = this.PhoneNumber,
ContactAddress = new AddressDataObject
{
Country = ContactAddress_Country,
State = ContactAddress_State,
City = ContactAddress_City,
Street = ContactAddress_Street,
Zip = ContactAddress_Zip
},
DeliveryAddress = new AddressDataObject
{
Country = DeliveryAddress_Country,
State = DeliveryAddress_State,
City = DeliveryAddress_City,
Street = DeliveryAddress_Street,
Zip = DeliveryAddress_Zip
}
};
}
}
#endregion
}
资料汇总:
@RenderBody、@RenderSection、@RenderPage、Html.RenderPartial、Html.RenderAction的作用和区别
【Asp.net MVC ---杂七杂八】的更多相关文章
- 26、ASP.NET MVC入门到精通——后台管理区域及分离、Js压缩、css、jquery扩展
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 有好一段时间没更新博文了,最近在忙两件事:1.看书,学习中...2.为公司年会节目做准备,由于许久没有练习双截棍了,难免生疏,所以现在临时抱 ...
- ASP.NET MVC 自我总结的便捷开发实例
前言 工作了这么久了,接触ASP.NET MVC已经很久了,一直都想总结一下它的一些实用的,经常使用的一些技巧,但是因为一直都很懒,也不想总结,所以一直都没有好好写出来,趁着现在有这种冲劲,那么就先把 ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库
在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...
- 使用Visual Studio 2015 开发ASP.NET MVC 5 项目部署到Mono/Jexus
最新的Mono 4.4已经支持运行asp.net mvc5项目,有的同学听了这句话就兴高采烈的拿起Visual Studio 2015创建了一个mvc 5的项目,然后部署到Mono上,浏览下发现一堆错 ...
- 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino
大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...
- Asp.net MVC 传递数据 从前台到后台,包括单个对象,多个对象,集合
今天为大家分享下 Asp.net MVC 将数据从前台传递到后台的几种方式. 环境:VS2013,MVC5.0框架 1.基本数据类型 我们常见有传递 int, string, bool, double ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之目录导航
ASP.NET MVC with Entity Framework and CSS是2016年出版的一本比较新的.关于ASP.NET MVC.EF以及CSS技术的图书,我将尝试着翻译本书以供日后查阅. ...
- ASP.NET MVC开发:Web项目开发必备知识点
最近加班加点完成一个Web项目,使用Asp.net MVC开发.很久以前接触的Asp.net开发还是Aspx形式,什么Razor引擎,什么MVC还是这次开发才明白,可以算是新手. 对新手而言,那进行A ...
随机推荐
- UI3_UICollectionViewMuti
// AppDelegate.m // UI3_UICollectionViewMuti // // Created by zhangxueming on 15/7/16. // Copyright ...
- WCF之并发,吞吐量和限流
并发 Single重入模式.对于每一个服务实例,同一时刻只能处理一个请求,其他对该实例的请求被排队. PerCall,每一线程会分配一个新的服务实例上.不会有并发性问题.不影响吞吐量. PerSess ...
- 关联表映射 Association Table Mapping
把关联保存为一个表,存储关联表的外键 在对象中,使用集合作为域值,来处理多值域. 而在DB中,只能有单值域. 外键映射的核心,是在关联关系的单值端使用外键来维持联系. 而在多对多的关联关系中,已经不存 ...
- [javascript|基本概念|Underfined]学习笔记
Underfined类型的值:underfined(只有一个) 1/声明未初始化 e.g.:var msg;-->msg == underfined:true 2/申明并值初始化为underfi ...
- 《DNS的正向反向解析》RHEL6
DNS的正向解析: Iptables –F Setenforce 0 安装DNS服务器的软件包: 启动DNS服务器: 修改DNS的配置文件:vim /etc/named.conf 修改DNS的配置:( ...
- js设计模式(3)---桥接模式
0.前言 看设计模式比较痛苦,一则是自己经验尚浅,不能体会到使用这些设计模式的益处:二则是不能很好把握使用这些设计模式的时机.所以这一部分看得断断续续,拖拖拉拉,为了了却这快心病,决定最近一口气看完几 ...
- 基础学习总结(八)--Intent中显示意图和隐式意图的用法
Intent(意图)主要是解决Android应用的各项组件之间的通讯.Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组 ...
- 【转】AOP知识点
ref:http://www.diybloghome.com/prology/975.html 一.概念理解 老规矩,还是先看官方解释:AOP(Aspect-Oriented Programming, ...
- Git客户端TortoiseGit(Windows系统)的使用方法
本文环境: 操作系统:Windows XP SP3 Git客户端:TortoiseGit-1.8.8.0-32bit 一.安装Git客户端 全部安装均采用默认! 1. 安装支撑软件 msysgit: ...
- 使用Eclipse开发,Java Compiler中Annotation Processin不出现的解决方案
第一步:在Eclipse菜单栏中点击Help,在点击inatall New Software 第二步:在Work with中找到 Juno - http://download.eclipse.org/ ...