1

I have two text inputs, content of which needs to be passed to a certain action as parameters when a button is clicked. I'm using MVC3 View:

<input name="input2" type="text"  class="inputfield" id="datepicker_1" /></td>
<input name="input2" type="text"  class="inputfield" id="datepicker_2" /></td>

@Html.Action("Search", ...)

Controller: public ActionResult Search(...) I suppose the object routeValues or RouteValueDictionary should be used in the @Html.Action for this. These object are confusing for me a bit. Could anyone clarify this for me please. Thank you!

1
  • Your question is confusing for me a bit. Could you please clarify you question? I mean, what exactly is your problem? Do you mean passing que parameters to the action? Commented Sep 20, 2011 at 18:37

2 Answers 2

2

The Html.Action will probably generate the link html before you provide the inputs. You need to either place your inputs inside a form to be submited to your action, or use ajax, with jquery perhaps, to call the action, like so:

@using (Html.BeginForm("Search", "Controller", FormMethod.Post, new { id = "frmAction" }))
{
    <input name="datepicker_1" type="text"  class="inputfield" id="datepicker_1" /></td>
    <input name="datepicker_2" type="text"  class="inputfield" id="datepicker_2" /></td>
}


[HttpPost]
public ActionResult Search(Datetime datepicker_1, Datetime datepicker_2) {...}

For an Ajax example, check this question:

jquery ajax forms for ASP.NET MVC 3

Hope this helps...

Sign up to request clarification or add additional context in comments.

1 Comment

@mishap be carefull these 2 line must be inside this block using (Html.BeginForm("Search", "Controller", FormMethod.Post, new { id = "frmAction" }))
0

It seems like you need have a submit on your view, and then implement a post action on your controller, to handle the submit. I.e. something along the lines of

 <input type="submit" value="Search..." />

in the view, and

[HttpPost]
public ActionResult Search(FormCollection collection)

the parameters depend on whether your view is strongly typed. The above assumes its not.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.