using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace MvcModelApp
{ [MetadataType(typeof(UserMetadata))]
public partial class tb_User
{
public string RePwd { get; set; }
} public class UserMetadata
{
[DisplayName("用户名")]
[Remote("NotExitesUserName", "Home")]
public string UserName { get; set; }
[DisplayName("备注")]
[DataType(DataType.MultilineText)]
public string Remark { get; set; }
[DisplayName("年龄")]
[Range(, )]
public int Age { set; get; } [DisplayName("密码")]
[PasswordPropertyText]
public string Pwd { get; set; } [PasswordPropertyText]
[DisplayName("重述密码")]
[System.Web.Mvc.Compare("Pwd")]
public string RePwd { get; set; } [Email]
public string Email { get; set; }
} public class EmailAttribute : RegularExpressionAttribute
{
public EmailAttribute()
: base(@"^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$")
{ }
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
这个是ADO.NET EF 自动生成的类
namespace MvcModelApp
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc; public partial class tb_User
{
public int ID { get; set; }
public string UserName { get; set; }
public string Remark { get; set; }
public int Age { get; set; }
public string Pwd { get; set; }
public string Email { get; set; }
} }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace MvcModelApp.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
private TestMvcEntities db = new TestMvcEntities();
public ActionResult Index()
{
var list = db.tb_User.ToList();
return View(list);
} public ActionResult Register()
{
tb_User model = new tb_User();
return View(model);
}
[HttpPost]
public ActionResult Register(tb_User model)
{
if (ModelState.IsValid)
{
db.tb_User.Add(model);
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View();
} }
[HttpGet]
public JsonResult NotExitesUserName()
{
string UserName = Request.Params["UserName"];
var user = db.tb_User.Where(c => c.UserName == UserName).FirstOrDefault();
return user == null ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
} public JsonResult TestArr(List<string> arr)
{
//string ss=
return Json(new {success= });
} }
}
@model IEnumerable<MvcModelApp.tb_User>

@{
ViewBag.Title = "Index";
}
<script src="~/Scripts/jquery-1.7.2.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<h2>Index</h2> <script type="text/javascript">
$(document).ready(function () { //$(":text").map(function () {
// alert($(this).val());
//}) var arr = new Array(); //var objstr = $(":text").map(function () {
// return $(this).text();
//}).get().join(","); $("#btnTest").click(function () {
// $(":text").each(function () { alert($(this).val());});
$("input[id^='txt']").each(function () {
arr.push($(this).val());
// alert($(this).val()); });
// var jsonobj = {"arr":arr,"ljj":"1"};
$.ajax({
type: "POST",
url: "@Url.Action("TestArr", "Home")",
data: JSON.stringify(arr),
contentType: "application/json",
success: function (data, status) {
alert(data);
}
}); // var str = arr.join(",");
// alert(str); }); });
// var obj = </script> <p>
<input type="text" id="txt1" />
<input type="text" id="txt2" />
<input type="text" id="txt3" />
<input type="text" id="txt4" /> <input id="btnTest" type="button" value="测试传递数组对象" /> </p> <p>
@Html.ActionLink("Register","Register", "Home")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.RePwd)
</th>
<th>
@Html.DisplayNameFor(model => model.UserName)
</th>
<th>
@Html.DisplayNameFor(model => model.Remark)
</th>
<th>
@Html.DisplayNameFor(model => model.Age)
</th>
<th>
@Html.DisplayNameFor(model => model.Pwd)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th></th>
</tr> @foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.RePwd)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Remark)
</td>
<td>
@Html.DisplayFor(modelItem => item.Age)
</td>
<td>
@Html.DisplayFor(modelItem => item.Pwd)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
} </table>
@model MvcModelApp.tb_User

@{
ViewBag.Title = "Register";
}
<script src="~/Scripts/jquery-1.7.2.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<h2>Register</h2>
@using (Html.BeginForm("Register","Home",null,FormMethod.Post,new {id="form1"}))
{
<table>
<tr>
<td>@Html.Display("UserName")</td>
<td>@Html.TextBoxFor(x=>x.UserName)@Html.ValidationMessageFor(x=>x.UserName)</td>
</tr>
<tr>
<td>@Html.DisplayFor(x=>x.Age)</td>
<td>@Html.TextBoxFor(x=>x.Age)@Html.ValidationMessageFor(x=>x.Age)</td>
</tr>
<tr>
<td>@Html.DisplayFor(x=>x.Pwd)</td>
<td>@Html.TextBoxFor(x=>x.Pwd)@Html.ValidationMessageFor(x=>x.Pwd)</td>
</tr>
<tr>
<td>@Html.DisplayFor(x=>x.RePwd)</td>
<td>@Html.TextBoxFor(x=>x.RePwd)@Html.ValidationMessageFor(x=>x.RePwd)</td>
</tr>
<tr>
<td>@Html.DisplayFor(x=>x.Email)</td>
<td>@Html.TextBoxFor(x=>x.Email)@Html.ValidationMessageFor(x=>x.Email)</td>
</tr>
<tr>
<td>@Html.DisplayFor(x=>x.Remark)</td>
<td>@Html.TextBoxFor(x=>x.Remark)@Html.ValidationMessageFor(x=>x.Remark)</td>
</tr>
<tr>
<td colspan=""><input type="submit" value="注册"/></td>
</tr> </table>
}

最新文章

  1. js 倒计时实现
  2. 打字机游戏Ⅱ之手速pk
  3. [Xamarin] 關於Internal Storage ,存取App內部使用資料 (转帖)
  4. 浅谈C中的指针和数组(二)
  5. 转:CSS布局奇淫技巧之-宽度自适应
  6. SQL__用命令删除定期的备份数据库文件
  7. picker控件详解与使用,(实现省市的二级联动)
  8. ASP.NET CORE小试牛刀:干货(完整源码)
  9. Python自动化中的键盘事件
  10. datatable的select()结果直接修改,会体现在表上
  11. Mybatis注解和配置文件命名规范所引发的问题
  12. Hdoj 1086.You can Solve a Geometry Problem too 题解
  13. CodeLite C/C+ IDE更新放出
  14. 如何判断一个请求为ajax请求?
  15. # 20155327 2016-20017-3 《Java程序设计》第3周学习总结
  16. HDU 2086 P - A1 = ?(推表达式)
  17. Vue教程:指令与事件(二)
  18. ArrayList之扩容与迭代器
  19. 执行存储过程比即时SQL执行慢的解决方案
  20. 【转】Python获取当前系统时间

热门文章

  1. MySQL表结构导出Excel
  2. ajax发送GET和POST请求
  3. php 基础 获取远程连接
  4. Python 之并发编程之线程下
  5. 模块学习--random
  6. Oracle个人自学笔记
  7. development tool
  8. Java Reflection (JAVA反射) --转载
  9. linux搭建mysql时ifconfig命令无法使用问题
  10. ch3 盒模型、定位