保存按钮点击功能在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=SSDEV6SQLEXPRESS");
    {
            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=SSDEV6SQLEXPRESS");
    {
            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按钮时,它应该转到我的控制器中的Edit方法。。。。。我在这里做错了什么。。。。。。。。。

是否支持有两种形式?

<% 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>

最新更新