zoukankan      html  css  js  c++  java
  • 控制器中的Action方法,接收浏览器传过来的参数,总共有几种?

    1.根据配置文件中的URL规则

    public ActionResult Delete(int id)    //id参数就是根据路由里面的参数id来传过来的,这个action方法中的参数一定要和路由中的id参数一样,大小写无所谓
    {
    
    }

    2.Mdel(模型绑定)(一般是通过Post方式,来接收参数)

     <td><input type="text" name="s_Name" value="@Model.s_Name" /></td> @*文本框的name属性也使用和Model.s_Name一样,模型绑定*@
     [HttpPost]
            public ActionResult Modify(Student model)  //这就是模型绑定了。
            {
                //将要修改的值,放到数据上下文中
               DbEntityEntry entry= db.Entry<Student>(model);
               entry.State = EntityState.Unchanged;
               entry.Property("s_Name").IsModified = true;
               entry.Property("c_ID").IsModified = true;
               db.SaveChanges(); //将修改之后的值保存到数据库中
               return Redirect("Index");
            }

    3.Request.Form[""]  或者Resuest.QueryString()

    public ActionResult Test()
    {
    Request.Form["name"];
    }

    4.FormCollection 

    public ActionResult Test(Formcollection form)
    {
    form["name"];
    }

    其中,3和4用法雷同,只不过语法不一样。

  • 相关阅读:
    对坐标点的离散化
    线段树-离散化处理点
    树状数组
    线段树
    dfs
    vector
    go 参数传递的是值还是引用 (转)
    go 数组指针 指针数组
    go 协程
    go 接口实现
  • 原文地址:https://www.cnblogs.com/caofangsheng/p/4926505.html
Copyright © 2011-2022 走看看