简体   繁体   English

Mvc Telerik按钮事件

[英]Mvc Telerik Button Event

I want to navigate to another action NewPage in Home Controller when somebody click on the following button. 当有人点击下面的按钮时,我想导航到Home Controller中的另一个动作NewPage。

<input class="t-button AlignButton" type="button" value="New" />

What would be the code for performing this action. 执行此操作的代码是什么? Thanks in advance. 提前致谢。

It might be better to use an ActionLink. 使用ActionLink可能更好。

@Html.ActionLink("New", "NewPage", "Home")

If you want it to look like a button, you can add css properties. 如果您希望它看起来像一个按钮,您可以添加css属性。

@Html.ActionLink("New", "NewPage", "Home", new { @class="newpage" })

In the css, you can define what you want the link to look like including using an image. 在css中,您可以定义链接的外观,包括使用图像。

I use such solutions: 我用这样的解决方案:

@(Html.Kendo().Button()
    .Name("CreateDataSubmit")
    .Content("Create new")
    .Events(e => e.Click(@<text>function(e) { window.location.href = "@(Url.Action("Create"))" }</text>))
)

@Html.ActionLink("Create new", "Create", null, new { @class = "k-button k-button-icontext" })

The second one is better. 第二个更好。 Good luck. 祝好运。

There are few options. 几乎没有选择。 You can do what Daniel suggested or you could do it using JavaScript. 您可以执行Daniel建议的操作,也可以使用JavaScript执行此操作。

Note navigation would not work in a browser that doesn't have JavaScript capability. 注意导航在没有JavaScript功能的浏览器中不起作用。

Add Id to the button 将ID添加到按钮

<input class="t-button AlignButton" type="button" value="New" id="my-button" url="@Url.Action("Action", "Controller")" />

Use JavaScript to find the button and do the url change. 使用JavaScript查找按钮并进行网址更改。 Here is a jQuery version 这是一个jQuery版本

$(document).ready(function () {        
    $('#my-button').click(function (e) { 
        var url = $(this).attr('url');
        windows.location = url;
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM