Reputation: 113
I'm having a problem with simple form-model binding. The customCepTelefonu attribute is null inside viewModel on debugging. However Post seems to sending the correct data with correct format (Checked with the Request method)
What am I missing here?
Controller
[HttpPost]
public ActionResult UpdateEmployee(EmployeeUpdateViewModel viewModel) **In viewModel customCepTelefonu is Empty**
{
var value = Request["EmployeeUpdateViewModel.customCepTelefonu"]; **With the old way i can get the data**
....
}
Model;
public class EmployeeUpdateViewModel
{
public int referans { get; set; }
public string customTelefon { get; set; }
public string customCepTelefonu { get; set; }
public string customKisaNumara { get; set; }
public string customCepKisaNumara { get; set; }
public DateTime dogumTarihi { get; set; }
public HttpPostedFileBase ImageUpload { get; set; }
}
View;
@using (Html.BeginForm("UpdateEmployee", "Home", FormMethod.Post))
{
@Html.TextBoxFor(p => p.EmployeeUpdateViewModel.customCepTelefonu)
<button type="submit">Save</button>
}
Upvotes: 0
Views: 754
Reputation: 1449
Your @Model in the view is not an EmployeeUpdateViewModel
.
You need to change the parameter in the UpdateEmployee
Method to the same type as your @Model
is.
Upvotes: 2