我正在尝试从一个视图中获取值,我有下面的代码,我从视图输入文本框中取出开始日期值并将其发回,但除了apikey和userkey之外我仍然是null。这里是两种观点..
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
}
答案 0 :(得分:2)
尝试更改文本框名称,以便模型活页夹可以将字段映射到模型。
<%= Html.TextBox("StartDate", Model.StartDate) %>
另外,是完整的代码,还是有aspikey和userid的隐藏文本字段?