从点击一个按钮,在ASP.NET MVC调用操作方法操作方法、按钮、NET、ASP

由网友(等一个不归人)分享简介:我想知道我是否可以在控制器中调用一个方法是单击按钮时。 I want to know if I can call a method in the controller when a button is clicked. 我有一个名为视图家居和视图加载时,它调用在该首页操作方法控制器。我有一个按钮(HTML或ASP....

我想知道我是否可以在控制器中调用一个方法是单击按钮时。

I want to know if I can call a method in the controller when a button is clicked.

我有一个名为视图家居和视图加载时,它调用在该首页操作方法控制器。我有一个按钮(HTML或ASP.NET)名为 LoadData 。当我按一下按钮,我需要加载一些数据调用相同的观点首页

I have a view called home and when the view is loaded, it invokes the Index action method in the controller. I have a Button (HTML or ASP.NET) called LoadData. When I click the button, I need to load some data in the same view called Home.

我该怎么办呢?

推荐答案

通过按钮,它涉及JQuery的或JavaScript打电话到从服务器获取数据,如果你想这样做的AJAX形式。但是,在最简单的形式,这样做的:

With buttons, it has to involve JQuery or JavaScript to make a call to get the data from the server, if you want to do it in AJAX form. But in its simplest form, doing:

<% Html.BeginForm("Action", "Controller"); %>

 <!--Form values in here-->

 <input type="submit" />

<% Html.EndForm(); %>

将调用您的操作方法,并调用回发。有一个在System.Web.Mvc.Ajax一个AJAX选择使用与AJAX选项的当作ajaxForm做回发异步,而且很容易安装。我倾向于使用jQuery,而不是个人。

Will invoke your action method and invoke a postback. There is an AJAX option in the System.Web.Mvc.Ajax to use an AjaxForm with AJAX options for doing the postback async, and it's easy to setup. I tend to use JQuery instead personally.

HTH。