MVC基礎簡單操作

1、刪除

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Index</title>
    <script type="text/javascript">
        function del(id) {
            if (confirm("Are you sure?")) {
                window.location = "default/del/1";
            }
        }
    </script>

</head>
<body>
    <div>
    <a href="javascript:del(1)">sc</a>
    </div>
</body>
</html>


再添加新的控制器,但不需要生成頁面了。直接寫操作方法

  public ActionResult del(int id)
        {
            //Response.Write("<script>alert('刪除"+id+"!')</script>");
            return Content("<script>alert('刪除" + id + "!')</script>");
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章