首页 > 代码库 > 学习笔记25_MVC前台API

学习笔记25_MVC前台API

**当请求url的规则有所改变时,前台的所有超链接的href都得改,为了避免多处修改,可以href = "http://www.mamicode.com/< %=url.Action("Controller","Action")%>"

**在Aspx页面当中,有一些较好用的Api,能再给用户呈现标签:

如:直接在某处写 <%=html.ActionLink("登录","LoginController","LoginAction");%> 那么,就可以给用户<a href="http://www.mamicode.com/LoginController/LoginAction">登录</a>

//也能够使用ActionLink设置ID,样式等等

如:使用<%=html.DropDownList("CityList");%>,就能在前台生成下拉列表,但是,在后台中,要

ViewData["CityList"] = new List<City> {.....}

如:使用<%=html.TextBox("key")%> ,就能<TextBox><%=ViewData["Key"];%></TextBox>

*也能自定义html的扩展方法,publc static String MyApi(this.htmlHelper helper , ...){ return html;} ,注意,要在<%@ import nameSpace ="xxxx"%>

***使用<%: C#Code%>来代替<%= C#Code%>,能使得浏览器不会解析由C#所产生的html标签

***在前台中,也能像后台一样自由编程,如在一行中,写<% var obj = ViewData["key"]  as xxxClass%> ,还能在其他行中,编写<% = obj.Method()%> 

 

学习笔记25_MVC前台API