AspNet MVC2 学习笔记

HtmlHelper

 

Html.ActionLink

 

  调用同一controller的另一个action (假设现在已导航到HomeController下)

  
    
<%= Html.ActionLink( " 首页 " , " Index " ) %>
带参数:
<%= Html.ActionLink( " 首页 " , " Index " , new { id = 1 }) %>

  客户端结果:

  
    
< a href = " /Home/Index " > 首页 </ a >
<a href="/Home/Index/1">首页</a>

 

   调用另一个controller的另一个action

  
    
<%= Html.ActionLink( " 登录 " , "LogOn ","Account" ) %>

  客户端:

  
    
< a href = " /Account/LogOn " > 登录 </ a >

 

 Form表单

  
    
<% Html.BeginForm( " DoRelease " , " Announce " , FormMethod.Post); %>
// 表单内容
<% Html.EndForm(); %>

 

 Action重名,添加 ActionNameAttribute 属性声明

  
    
[ActionName( " View " )]
public ActionResult ViewSomething( string id)
{
// TODO:
return View();
}

 

AcceptVerbsAttribute

 

  
    
[HttpGet]
public ActionResult Edit( string id)
{
return View();
}

[HttpPost]
public ActionResult Edit( string id, string name)
{
// TODO:
return View();
}

 

 

 Html.Hidden

  
    
<%= Html.Hidden( " isname " , " isvalue " ) %>

 

Html.RouteLink

Html.EditorFor

  Html.EditorFor()辅助方法可以用于任何数据类型值。在默认情形下,它很聪明,会根据要编辑的类型输出合适的HTML < input/>元素。譬如:

  <%: Html.EditorFor(model=>model.Email) %>  输出:  <input class="text-box single-line" id="Email" name="Email" type="text" value="gggg" />

如果这个属性是布尔值类型,会生成< input type=”checkbox”/>元素

  除了支持简单的数据类型外,Html.EditorFor()辅助方法还允许你传递给它拥有多个属性的比较复杂的对象。在默认情形下,它会对对象的所有公开属性进行循环,输出< label>, < input/> 元素,以及它能找到的每个属性的任何合适的验证消息。例如,对Customer对象只做单个Html.EditorFor()调用,会针对各个属性输出< label>, < input/> 元素,以及ValidationMessage验证块。

 

弹出 js:

参考:http://stackoverflow.com/questions/1934274/mvc-jquery-linq-to-sql-delete-with-confirmation-and-redirect-on-success

你可能感兴趣的:(学习笔记)