一,如果是虚拟服务器的话,那得这么配置:
// 4.注意: 将1标的规则更改为 "{controller}.mvc/{action}/{id}" 即可
// 自行支持 IIS6 and IIS7 两种模式
// 笔者注:一般的虚拟主机不支持.mvc,.aspx也要检查文件存在
// 变通方法为可以将.mvc换成.ashx或.asbx
二,url的变革:
post.aspx?year=1999&month=3&day=8 的参数URL变为
/post/1999/3/8/ 这样的简短漂亮且有意义的URL
三,新建view的快捷方式
在controler上右键,新建
四,url的参数问题,必须与route参数同名
public ActionResult Index(string id)
ViewData["chsword"] = id;
/Eice/Index/HellowEice,
五,返回其他的ActionResult
1,返回Ascx
public ActionResult Ascx()
{
return PartialView();
}
2,返回文本
public ActionResult Text(){
return Content("这是一段文本");
}
3,返回json
public ActionResult ShowJson()
{
var m = new EiceIndexModel
{
Name = "邹健",
Sex = true
};
return Json(m);
}返回文本:
{"Name":"邹健","Sex":true}
4,输出JS文件
public ActionResult Js()
{
return JavaScript("var x=0;");
}
5,页面跳转
1.跳转到Url
public ActionResult rdurl()
{
return Redirect("http://www.baidu.com");
}2.跳转到Action
public ActionResult rdaction()
{
return RedirectToAction("Index","Eice");
}3.跳转到Routing规则
public ActionResult rdrouting()
{
return RedirectToRoute("Default",//Route名
new{
Controller = "Eice",
Action = "Index"
});
}
六,HTML的一些方法
<%=Html.ActionLink("首页","Index","Home")%>
<%using(Html.BeginForm("index","home",FormMethod.Post)){%>
表单内容<%} %>
<%=Html.TextBox("t1","重典") %>
更简单的绑定 ViewData["t1"]="重典";在control里这么写
七,如何转向NotFound页面
return View("NotFound", "Site", "Shared");
八,Details(int id)的action的设计
public ActionResult Details(int id)
{
var entity = bll.FindByID(id);