运行服务器端方法/流程OnClick [英] Running a Server Side Method/Process OnClick

查看:76
本文介绍了运行服务器端方法/流程OnClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新手.我已经在其中一个视图(引导程序)中定义了一个按钮:

I am new to MVC. I have defined a button in one of my views (bootstrap):

<button type="button" class="btn btn-success btn-lg">
    <span class="glyphicon glyphicon-star"></span> Star
</button>

现在,我想在单击此按钮时执行一些服务器端代码,但是我不确定如何在 MVC项目中执行该操作.应该在哪里放置服务器端代码,我该如何称呼它?我正在使用 Razor .

Now, I want to execute some server side code when this button is clicked however I am not sure how to do it in an MVC project. Where should place the server side code and how should I call it ? I am using Razor.

推荐答案

您最好的选择是在第一个实例中查看jquery/ajax,因为实例很多.SO上的许多例子都暗示了这种模式.以下是帮助您快速入门的快速草图.

your best bet is to look at jquery/ajax in the 1st instance as there are many. many examples on SO that allude to this pattern. Below is a quick sketch to get you going.

$(function() {
    $('.btn-success').on('click', function() {
        $.ajax({
            url: "your url in ironpython",
            data: {datavariable:somedatatosend},
            context: document.body
        }).done(function() {
            // update any divs required here with the
            // returned json result (or text)
            $(this).addClass("done");
        });
    };
};

如果您的目标网址是mvc,则可以将上面的url参数替换为:

if your target url was mvc, then you'd replace the url parameter above with something like:

url: '@Url.Action("myAction","myController")'

这篇关于运行服务器端方法/流程OnClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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