大家好,我有一个表格,我有一个添加新项目链接...当我点击它时,它会将我带到一个创建页面,其中我有用于插入新记录的文本框和一个创建按钮..但我点击创建按钮它不工作任何人都可以帮助我我在哪里做错了这是我的代码
这是我的 create.aspx 页面:
<%: ViewBag.Title="Create" %>
<fieldset>
<legend>Projects</legend>
<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="Create" />
</p>
</fieldset>
这是我的控制器功能:
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(ProjectModel model)
{
var modelList = new List<ProjectModel>();
using (SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True"))
{
conn.Open();
SqlCommand insertcommande = new SqlCommand("Sp_AddNewProject", conn);
insertcommande.CommandType = CommandType.StoredProcedure;
insertcommande.Parameters.Add("@ProjectName", SqlDbType.VarChar).Value = model.projectName;
insertcommande.Parameters.Add("@Description", SqlDbType.VarChar).Value = model.Description;
insertcommande.Parameters.Add("@Status", SqlDbType.VarChar).Value = model.status;
insertcommande.ExecuteNonQuery();
}
return View( modelList);
}
当我单击aspx页面中的创建按钮时,它应该在我的控制器中创建方法.....我在这里做错了什么............