开发者

Is a Strongly Typed Html.Telerik().DatePicker() possible in ASP.NET MVC in a Html.BeginForm()?

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
    }
}


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
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜