在 MVC3 中,我创建了一个注册表单。我创建了一个模型、控制器和视图。这是我的代码:
[HttpGet]
public ActionResult Insert()
{
Models.Employees objEmpl = new Models.Employees();
return View(objEmpl);
}
[HttpPost]
[AcceptVerbs("Post")]
public ActionResult Insert(Models.Employees objs)
{
var v = new Models.test().InsertDl(objs);
return View();
}
The above is my controller
@model MvcVideo.Models.Employees
@{
ViewBag.Title = "Insert";
Layout = "~/Views/Shared/VideoLayout.cshtml";
}
<h2>Insert</h2>
@using(Html.BeginForm("Insert","Home",FormMethod.Post ))
{
<table>
<tr>
<td>
Employee Name
</td>
<td>
@Html.TextBox("Ename",@Model.Enames)
</td>
</tr>
<tr>
<td>
Department Id
</td>
<td>
@Html.TextBox("Departmentid",@Model.DepartId )
</td>
</tr>
<tr>
<td>
Email Id
</td>
<td>
@Html.TextBox("Emailid",@Model.EmailIds)
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
@Html.TextBox("Address",@Model.Adress)
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;" >
<button title ="Ok" value="OK"></button>
</td>
</tr>
</table>
}
但是action 方法参数objs
处的对象public actionresult Insert(models.Empoyees objs)
显示空值。意思是Ename=Null
,和Department=0
Emailid=Null
Address=null