首先先在Controller中建立一個Action(Aras),將這個Action當作我們的主頁面,右鍵Action名稱新增一個檢視(View)
再來進入前端View當中,新增前端四個CRUD的按鈕,個別利用using Html.BeginFrom包起來,生成的Form,再利用Post回傳Form至後端相對應的Action執行
@{
ViewBag.Title = "Aras";
}
<!DOCTYPE html>
<h1>Aras</h1>
@using (Html.BeginForm("Aras_Create", "CADs", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<button type="submit" id="create-button" class="btn btn-primary">新增</button>
}
@using (Html.BeginForm("Aras_Read", "CADs", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<button type="submit" id="read-button" class="btn btn-primary">讀取</button>
}
@using (Html.BeginForm("Aras_Update", "CADs", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<button type="submit" id="upload-button" class="btn btn-primary">修改</button>
}
@using (Html.BeginForm("Aras_Delete", "CADs", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<button type="submit" id="delete-button" class="btn btn-primary">刪除</button>
}
[HttpPost]
public ActionResult Aras_Create()
{
Connection con = new Connection();
Innovator inn = con.Connect();
Item CAD = inn.newItem("CAD", "add");
CAD.setProperty("item_number", "Aras");
CAD = CAD.apply();
return View("Aras");
}
[HttpPost]
public ActionResult Aras_Read()
{
Connection con = new Connection();
Innovator inn = con.Connect();
Item CAD = inn.newItem("CAD", "get");
CAD.setAttribute("where", "[CAD].item_number='Aras'");
CAD = CAD.apply();
string CAD_item_number=CAD.getProperty("item_number");
Response.Write("<script language=javascript>alert('"+ CAD_item_number + "');</"+ "script>");
return View("Aras");
}
[HttpPost]
public ActionResult Aras_Update()
{
Connection con = new Connection();
Innovator inn = con.Connect();
Item CAD = inn.newItem("CAD", "edit");
CAD.setAttribute("where", "[CAD].item_number='Aras'");
CAD.setProperty("item_number","Edit-Aras");
CAD = CAD.apply();
return View("Aras");
}
[HttpPost]
public ActionResult Aras_Delete()
{
Connection con = new Connection();
Innovator inn = con.Connect();
Item CAD = inn.newItem("CAD", "delete");
CAD.setAttribute("where", "[CAD].item_number='Edit-Aras'");
CAD = CAD.apply();
return View("Aras");
}