通过参数获取空值将值从视图传递给自身?

时间:2010-04-30 22:24:35

标签: asp.net-mvc views

我正在尝试从一个视图中获取值,我有下面的代码,我从视图输入文本框中取出开始日期值并将其发回,但除了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
     }

1 个答案:

答案 0 :(得分:2)

尝试更改文本框名称,以便模型活页夹可以将字段映射到模型。

<%= Html.TextBox("StartDate", Model.StartDate) %> 

另外,是完整的代码,还是有aspikey和userid的隐藏文本字段?