views:

26

answers:

1

Hi all, 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
     }
+2  A: 

Try changing the textbox name so that the model binder can map the field to your model.

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

Also, is that the full code, or do you have hidden text fields for aspikey and userid?

Lester
Thanks that worked.
Misnomer
But one thing would like to mention here if i have a object and then it has attribute.E.g. someobj and has value somevalue. So, I access it like somobj.somevalue rite...so in Html helper I have <%= Html.TextBox("somevalue",Model.someobj.somevalue)%> this code wont work but if i wrote <%= Html.TextBox("someobj.somevalue",Model.someobj.somevalue)%>then it works....just thought would mention this..
Misnomer