1、ASP.NET MVC 3 如何去除默认验证
示例代码:
{
public int ID { get ; set ; }
[Required(ErrorMessage = " 必须输入标题 " )]
public string Title{ get ; set ; }
[Required(ErrorMessage = " 必须输入发行日期 " )]
public DateTime ReleaseDate { get ; set ; }
[Required(ErrorMessage = " 必须制定种类 " )]
public string Genre{ get ; set ; }
[Required(ErrorMessage = " 必须输入票价 " )]
[Range( 1 , 100 ,ErrorMessage = " 票价必须在 1 到 100元之间 " )]
public decimal Price{ get ; set ; }
[StringLength( 5 ,ErrorMessage = " 最多允许输入5个字符 " )]
public string Rating{ get ; set ;}
public string Description { get ; set ; }
}
2、ASP.NET MVC 3在视图中如何创建HTML标签,(在视图中把含有标签的字符编译成相应的标签)
3、ASP.NET MVC 3 中 报错:mvc 3属性不能设置为“null”值。必须将该属性设置为类型为“Int32”的非 null 值。
4、数据库表需要加s
5、ASP.NET MVC 3 中如何使用单选按钮 RadioButton
6、ASP.NET MVC 3 中如何引用js文件
7、ASP.NET MVC 3 文本框自定义单击事件 onclick事件
8、ASP.NET MVC 3 使用下拉列表 DropDownList
控制器代码如下:
private CRMDBContext db = new CRMDBContext();
var list = db.Partments.ToList();
ViewData["partmentDDL"] = new SelectList(list, "Id", "PartName",employee.PartmentID);
视图中:
1、@Html.DropDownList(
"PartmentID"
,(SelectList)ViewData[
"partmentDDL"
],
"--this one--"
)
2、 @Html.DropDownListFor(model =>model.PartmentID,(SelectList)ViewData[
"partmentDDL"
],
"--this one--"
)
|
9、ASP.NET MVC 3
网上有人说是:错误主要原因是在提交处不认识原来的下拉列表(来自这里)他的解决方法是:在控制器中的接受处理的Action中重复构建DropDownList的代码,比如
public ActionResult Create() { var actionList = db.Actions.ToList(); ViewData["actionDDL"] = new SelectList(actionList, "Id", "GetMoActName"); var popedomList = db.Popedoms.ToList(); ViewData["pepedomDDL"] = new SelectList(popedomList, "Id", "Property"); return View(); } // // POST: /ActionPopedoms/Create [HttpPost] public ActionResult Create(ActionPopedoms actionpopedoms) { var actionList = db.Actions.ToList(); ViewData["actionDDL"] = new SelectList(actionList, "Id", "GetMoActName"); var popedomList = db.Popedoms.ToList(); ViewData["pepedomDDL"] = new SelectList(popedomList, "Id", "Property"); if (ModelState.IsValid) { db.ActinPopedoms.Add(actionpopedoms); db.SaveChanges(); return RedirectToAction("Index"); } return View(actionpopedoms); }
10、ASP.NET MVC 3 在Razor view页面中如何导入命名空间呢
@usingMyNamespace
@
using
MyNamespace
|
@
using
MyNamespace
|
@
using
MyNamespace
|
@
using
MyNamespace
|
@
using
MyNamespace
|
11、ASP.NET MVC 3中如何获得请求的Url路径
string
url =
""
;
//url全部分
url =HttpContext.Current.Request.Url.ToString();
|
12、ASP.NET MVC 3中
13、ASP.NET MVC 3 中使用单选按钮Radiobutton
这里为了应急所需,暂只介绍一种用法代码如下