I am trying to get values from a view which i have the code below and I am taking the start date value from the view input text box and posting it back but I am still getting null except for the apikey and userkey.Here are the two views..
public ActionResult View1(string apiKey, string userId)
{
StartGoalViewModel vm = new StartGoalViewModel();//this is a custom model..
vm.ApiKey = apiKey;
vm.UserId = userId;
vm.GoalTypeId =1;
vm.StartDate = null;
return View(vm);
}
VIEW1.ASPX
<% Html.BeginForm(); %>
<%= Html.TextBox("name", Model.StartDate) %>
<input type="submit" value="Start" />
<% Html.EndForm(); %>
[HttpPost]
public ActionResult VIEW1 (StartGoalViewModel fm)
{
// I get fm.StartDate and fmGoaltypeId null...
// fm.aspikey and fm.userid have values
}
Try changing the textbox name so that the model binder can map the field to your model.
Also, is that the full code, or do you have hidden text fields for aspikey and userid?