views:

33

answers:

3

Pretty Basic one here guys.

I have a View which holds 2 textfields for input and a submit button

<%using (Html.BeginForm("DateRetrival", "Home", FormMethod.Post)){ %>    
<%=Html.TextBox("sday")%>  
<%=Html.TextBox("eday")%>
<input type="submit" value="ok" id="run"/>
<% }%>

the following controller action which I want to bind the data input is as follows

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult DateRetrival()
    {
        return View();
    }


    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult DateRetrival(string submit)
    {


        return null;
    }

When I debug this and look in the action methods parameter, the value is null. When I've entered values in both textboxes and and clicked the submit method.

+2  A: 

Add parameters to catch each input field value.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DateRetrival(string sday, string eday)
{
    return null;
}
Developer Art
+2  A: 

Try:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DateRetrival(string sday, string eday, string submit)
{
    return null;
}

and if you want sumbit button value

<input type="submit" value="ok" id="run" name="submit"/>

If you want to have value posted, name attribute has to be set. Html.TextBox automatically sets name from parameter.

LukLed
+2  A: 

You probably want to do something like this:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult DateRetrival(string sday, string eday)
    {

        return null;
    }

Ideally, though you probably want to be passing a model to your controllers:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult DateRetrival(DateModel dates)
    {
        var date1 = dates.sday;
        var date2 = dates.eday;
        return null;
    }

See http://msdn.microsoft.com/en-us/library/dd394711.aspx

Dan Diplo