tags:

views:

121

answers:

1

Hi, I want to invoke an action (which is in HomeController) on link button click? The link button is present on a empty View which I have added to Views which is not a stronly typed view?

regards, kapil

+1  A: 

If you want to use a button then it needs its own form and the form helper method needs to show the controler and action you are using.

<% using (Html.BeginForm("ActionName", "ControllerName" )) { %>
<input type="submit" value="Run Action" />
<% } %>

Or, if you want to just use a text link then you can use this:

<%= Html.ActionLink("Link text", "ActionName", "ControllerName"); %>

If your view is for the same controler as the action you want to direct to then you do not need to specify the controller name.

If you wish to pass extra info to the action method you can pass an anonymous object like this:

<%= Html.ActionLink("Link text", "ActionName", "ControllerName", new {variableName="a value", anotherVariableName=78}); %>
Richard
Thanks Richards for your help.I used actionlink, it worked very well.But is there any way sothat i can pass any value to a controller action on a button click?
kapil
Have added an extra bit to my answer to answer you subsequent question.
Richard