从点击一个按钮,在ASP.NET MVC调用操作方法 [英] Invoke Action Method from Clicking a button in ASP.NET MVC

查看:196
本文介绍了从点击一个按钮,在ASP.NET MVC调用操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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。

这篇关于从点击一个按钮,在ASP.NET MVC调用操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆