2016-04-29 5 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データ値(ですどのボタンがクリックされたか)は送信されません。

関連する問題