我使用了MVC 5和MongoDB,我试图在表单提交的控制器中获取隐藏字段值(ObjectId)但是获取默认值(000000000000000000000000)而不是实际值(5af58cedf86bc82ab0e0f825)。
此处字段类型为ObjectId(MongoDB.Bson Type)
请帮助我,我是MongoDB的新手。 在此先感谢
@using (Html.BeginForm()) {
<div class="container ">
<div class="row">
@Html.HiddenFor(m => m.Employee._id, new { @Value = ObjectId.Parse(Model.Employee._id.ToString()) });
<div class="col-md-12">
<h3 class="text-center" style="margin: 25px 0;">
Employee Registration Form
</h3>
<h4 class="text-center" style="margin: 25px 0">
<span style="color:red">
@if (TempData["ErrorMessage"] != null)
{
@TempData["ErrorMessage"]
}
</span>
<span span style="color:forestgreen">
@if (TempData["SuccessMessage"] != null)
{
@TempData["SuccessMessage"]
}
</span>
</h4>
<div class="col-md-2 float-left"></div>
<div class="col-md-8 float-left">
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label>Employee First Name : </label> @Html.TextBoxFor(m => m.Employee.FirstName, new { @class = "form-control" })
</div>
<div class="col-md-6">
<label>Employee Last Name : </label> @Html.TextBoxFor(m => m.Employee.LastName, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label>Employee Contact No : </label> @Html.TextBoxFor(m => m.Employee.ContactNumber, new { @class = "form-control" })
</div>
<div class="col-md-6">
<label>Email Address : </label> @Html.TextBoxFor(m => m.Employee.Email, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label>Salary : </label> @Html.TextBoxFor(m => m.Employee.Salary, new { @class = "form-control" })
</div>
<div class="col-md-6">
<label>Gender: </label>
<div>
Male @Html.RadioButtonFor(m => m.Employee.Gender, "Male") Female @Html.RadioButtonFor(m => m.Employee.Gender, "Female")
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label>Designation: </label> @Html.TextBoxFor(m => m.Employee.Designation, new { @class = "form-control" })
</div>
<div class="col-md-6">
<label>Address: </label> @Html.TextAreaFor(m => m.Employee.Address, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-default" value="Save Employee" />
<input type="reset" class="btn btn-info" value="Cancel" />
</div>
</div>
<div class="col-md-2 float-left"></div>
<br />
<br />
<div class="col-md-12 float-left"></div>
<div class="col-md-1 float-left"></div>
<div class="col-md-10 float-left">
</div>
<div class="col-md-1 float-left"></div>
</div>
</div>
</div>
}