2016-04-29 67 views
0

我做了一個簡單的MVC程序。我創建了3個按鈕來插入,更新或刪除員工。但是當我點擊按鈕時,操作方法沒有被執行&相同的代碼如何在朋友的系統中工作,但不在我的系統中。我們都使用相同的MVC 4.這裏是行動方法沒有被執行,而點擊按鈕

控制器

public ActionResult Edit_Update_Delete_Insert_EMP() 
    { 

     EmployeeModel em = new EmployeeModel(); 
     ActionResult ar = View(em); 
     return ar; 
    } 

    [HttpPost] 
    public ActionResult Edit_Update_Delete_Insert_EMP(EmployeeModel em, string Employee) 
    { 
     if (Employee == "Insert") 
     { 
     } 
     if (Employee == "Update") 
     { 
     } 
     if (Employee == "Delete") 
     { 
     } 
     return null; 
    } 

查看

@model Deepak_MVC_1.Models.EmployeeModel 
@{ 
    Layout = null; 
} 
<!DOCTYPE html> 
<html> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
    <title>Edit_Update_Delete_Insert_EMP</title> 
</head> 
<body> 
    <div> 
     @using(Html.BeginForm()) 
     { 
      <table> 
       <tr> 
        <td>@Html.LabelFor(eid=>eid.E_ID)</td> 
        <td>@Html.TextBoxFor(eid=>eid.E_ID)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(fname=>fname.F_Name)</td> 
        <td>@Html.TextBoxFor(fname=>fname.F_Name)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(lname=>lname.L_Name)</td> 
        <td>@Html.TextBoxFor(lname=>lname.L_Name)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(age=>age.Age)</td> 
        <td>@Html.TextBoxFor(age=>age.Age)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(salary=>salary.Salary)</td> 
        <td>@Html.TextBoxFor(salary=>salary.Salary)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(dept=>dept.Dept)</td> 
        <td>@Html.TextBoxFor(dept=>dept.Dept)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(doj=>doj.Doj)</td> 
        <td>@Html.TextBoxFor(doj=>doj.Doj)</td> 
       </tr> 
      </table> 
     } 
      <button type="submit"name="Employee" value="Insert">Insert Employee</button> 
      <button type="submit"name="Employee" value="Update">Update Employee</button> 
      <button type="submit"name="Employee" value="Delete">Delete Employee</button> 
    </div> 
</body> 
</html> 
+1

您的提交按鈕不在表單中。將它們移動到'}'上方 –

回答

1

的按鈕是BeginForm() { }塊之外,所以Employee數據值(由下式確定碼該按鈕被點擊)未被提交。