ASP.NET MVC 3.0小知识积累

1、JsonResult

 1 using System.Web.Mvc;
2
3 //public ActionResult Index()
4 public JsonResult Index()
5 {
6 var province = from p in new Models.NorthwindDataContext().Province
7 select p;
8
9 return Json(new
10 {
11 page = 1,
12 total = province.Count(),
13 rows = province.ToList()
14 },
15 JsonRequestBehavior.AllowGet
16 );
17 }

2、Html Helper

@Html.TextBox("UserName")    <—>    <input id="UserName" type="text" value="" name="UserName">

@Html.TextBox("UserName", null, new { id = "txtUserName" })    <—>    <input id="txtUserName" type="text" value="" name="UserName">
@Html.TextBox("UserName", null, new { id = "txtUserName", style = "100px;" })    <—>    <input id="txtUserName" type="text" value="" style="100px;" name="UserName">

@Html.TextBox("UserName", null, new { id = "txtUserName", @class = "highlight" })    <—>    <input id="txtUserName" class="highlight" type="text" value="" name="UserName">

@Html.ActionLink("删除", "DeletePost", new { id = item.ID }, new { onclick = "return confirm('你确定要删除该随笔?')" })

原文地址:https://www.cnblogs.com/libingql/p/2435378.html