开发者

How to invoke a action on a link button click in ASP.Net MVC app?

I want to invoke an action (which is in HomeController) on link button click? The link开发者_StackOverflow社区 button is present on a empty View which I have added to Views which is not a stronly typed view?

regards, kapil


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}); %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜