2012-07-17 77 views
1

嗨,大家好,我有一個表,我有一個編輯項目鏈接...當我點擊它,它帶我到編輯頁面,我有文本框編輯記錄和一個按鈕保存..但我點擊保存按鈕它不工作任何一個可以幫助我在哪裏,我錯了這裏做什麼是我的代碼保存按鈕點擊功能不工作在mvc3?

這是我的Edit.aspx頁:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Gridview_BugTracker.Models.BugTracker_DataHelper>" %> 
<!DOCTYPE html> 

<html> 
<head runat="server"> 
<title></title> 
     <%: ViewBag.Title="Edit" %> 
</head> 
<body> 
     <div> 
      <% using (Html.BeginForm()) 
       { %> 
     <form action="Edit.aspx" method="post"></form> 

     <%:Html.ValidationSummary(true)%> 
     <fieldset> 
       <legend>Projects</legend> 

      <%:Html.HiddenFor(model => model.ProjectId)%> 

       <div class="editor-label"> 
        <%:Html.LabelFor(model => model.projectName)%> 
       </div> 
       <div class="editor-field"> 
         <%:Html.EditorFor(model => model.projectName)%> 
         <%:Html.ValidationMessageFor(model => model.projectName)%> 
       </div> 

       <div class="editor-label"> 
         <%:Html.LabelFor(model => model.Description)%> 
       </div> 
       <div class="editor-field"> 
         <%:Html.EditorFor(model => model.Description)%> 
         <%:Html.ValidationMessageFor(model => model.Description)%> 
       </div> 

       <div class="editor-label"> 
         <%:Html.LabelFor(model => model.status)%> 
       </div> 
       <div class="editor-field"> 
         <%:Html.EditorFor(model => model.status)%> 
         <%:Html.ValidationMessageFor(model => model.status)%> 
       </div> 
       <p> 
         <input type="submit" value="Save" /> 
       </p> 
     </fieldset> 
<%} %> 
       <%: Html.ActionLink("Back to List", "Index")%> 
     </div>  
</body> 
</html> 

這是我的控制器功能:

[AcceptVerbs(HttpVerbs.Get)] 
public ActionResult Edit(int id, BugTracker_DataHelper updatemodel) 
{ 
    SqlConnection editconn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugTracker;Data Source=SSDEV6\SQLEXPRESS"); 
    { 
      editconn.Open(); 
      SqlCommand ecmd = new SqlCommand("Select ProjectId,projectName,Description,status From Projects Where ProjectId=" + id, editconn);     
      SqlDataReader dr = ecmd.ExecuteReader(); 
      if (dr.Read()) 
      { 
        updatemodel.ProjectId = Convert.ToInt16(dr["ProjectId"]); 
        updatemodel.projectName = dr["projectName"].ToString(); 
        updatemodel.Description = dr["Description"].ToString(); 
        updatemodel.status = dr["status"].ToString(); 
      } 
      else 
      { 
        dr.Close(); 
      } 
      dr.Close(); 
      editconn.Close(); 
      return View(updatemodel); 
    } 
} 

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Edit(BugTracker_DataHelper updatemodel, FormCollection collection, int id) 
{ 
    SqlConnection editconn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugTracker;Data Source=SSDEV6\SQLEXPRESS"); 
    { 

      SqlCommand ecmd = new SqlCommand("EditGetList", editconn); 
      ecmd.CommandType = CommandType.StoredProcedure; 
      editconn.Open(); 
      ecmd.Parameters.Add("projectID", SqlDbType.Int).Value = updatemodel.ProjectId; 
      ecmd.Parameters.Add("projectName", SqlDbType.VarChar).Value = updatemodel.projectName; 
      ecmd.Parameters.Add("Description", SqlDbType.VarChar).Value = updatemodel.Description; 
      ecmd.Parameters.Add("Status", SqlDbType.VarChar).Value = updatemodel.status; 
      editconn.Close(); 

      return View(updatemodel); 
    } 
} 

當我在aspx頁面SAVE按鈕,單擊它應該去編輯方法在我的控制器.....我在做什麼錯在這裏.........

+0

如果你把一個斷點在帖子編輯動作它被擊中?除非您修改了路線,否則您的表單操作是edit.aspx,看起來不正確。 – 2012-07-17 09:34:51

+0

請參閱下面的答案。你昨天的問題也與此類似,我回答了。我的答案是否有效?如果是這樣,你需要接受人們的答案。乾杯。 – 2012-07-17 09:45:39

+0

@Rory ....已編輯頁面來了edid的數據,但編輯數據時,並單擊保存按鈕不工作.... – 2012-07-17 09:54:40

回答

0

你假設有兩種形式?

<% using (Html.BeginForm()) 
{ %> 
    <form action="Edit.aspx" method="post"></form> 

或者你是否試圖設置BeginForm的動作?

您按下的按鈕實際上是第一種形式的一部分,而不是第二種。

所以這

<form action="Edit.aspx" method="post"></form> 

目前沒有做非常多。

如果你想保存按鈕是做什麼的第二種形式,那麼你將需要把按鈕表單標籤裏面,像這樣:

<form action="Edit.aspx" method="post"> 
    <input type="submit" value="Save" /> 
</form>