MVC学习笔记

一,如果是虚拟服务器的话,那得这么配置:
// 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);

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值