views:

71

answers:

1

I have a section of a view that I would like to submit to an action so it is setup inside a Html.BeginForm()

I am trying to also make use of the Html.Telerik().DatePicker() control and would like it also to strongly type linked inside the form, same as the DropDownListFor, is this possible?

<% using (Html.BeginForm("MyAction", "Responding")) { %>

    <%= Html.DropDownListFor(m => m.SelectedItem, Model.MyItems) %>
    <!--list works fine-->

    <% Html.Telerik().DatePicker()
            .Name("datePicker")
            .Render(); %>  
    <!--how do I get this strongly-type-linked?-->

    <input type="submit" value="submit" />
<% } %>

The model for the view has the appropriate properties:

public int SelectedItem { get; set; }
public string SelectedDate { get; set; }

Controller code:

public class RespondingController : Controller
{
    [HttpGet]
    public ActionResult MyAction(int SelectedItem, string SelectedDate)
    {
        //on the form submit SelectedItem value arrives
        //need SelectedDate to do the same
    }
}
+1  A: 

Your parameter is incorrect. it needs to be named the same as the name value you gave to the control e.g 'datePicker'.

public class RespondingController : Controller
{
    [HttpGet]
    public ActionResult MyAction(int SelectedItem, DateTime? datePicker)
    {
        //on the form submit SelectedItem value arrives
        //need SelectedDate to do the same
    }
}
redsquare
thanks for catching my mis-matched parameter naming :)
Nick Josevski

related questions